Show me the code
path <- here("raw_data", "data_import_exercises", "Kronisk smerte - udvikling.csv")
read.csv(path)
read.csv2(path)
read_csv2(path)Steen Harsted & Søren O’Neill
August 17, 2025
You can download the course slides for this section here

By now:
here() functionsolders.csv and assigned it to an object called soldiersIf not, we suggest you go to “Project Discipline” and complete the Setting up your course project section.
This is all you need to know for this course.
The following exercises will introduce you to importing file types other than .csv. These exercises are optional, and not required to complete the rest of the course.
raw_data directoryThe unzipped folder contains:
Frame and Time_Seconds are time variablesCGY gives you the height (in mm) of their center of gravitychallenge that you need if you want to solve the challenge assignmentTry these functions:
read.csv()read.csv2()read_csv2()id_age.csv and id_sex.dta, combine them (use full_join()), and assign the combined dataframe to an objecttidyverse includes the haven package that can read Stata´s .dta fileshaven::read_dta()dplyr function full_join() will help you to combine the two imported objects.a <- haven::read_dta(here("raw_data", "data_import_exercises", "id_sex.dta"))
b <- read_csv2(here("raw_data", "data_import_exercises","id_age.csv")) %>%
rename(ID = id) # Rename the id column
df_descriptives <- full_join(a, b)
rm(a,b) # Remove the objects a and b so that your environment is less crowdedlist.files() to generate an object called files containing the filenames of the 19 motioncapture filespattern =argument in list.files()
, pattern = NULL # The default setting. List all files in our directory
, pattern = ".csv$" # all files in our directory that ends with ".csv"
, pattern = "^desc" # all files in our directory that starts with "desc"
, pattern = "[0-9].csv$" # all files in our directory that ends with "[a number from 0-9].csv"file = should include the path to the folder (use here()), and the files object you just created.df_descriptives object you created beforeYou will learn the code to do this later in the course. * Change ID to a factor * Change sex to a factor with levels = c(1,2), labels = c("Boy", "Girl") * Change age from months to years * Retain the row with the highest value of CGY for each of the children
challengevroom and load itvroom is a very fast package for importing .csv files. (hence the name)vroom package is vroom()vroom() has the argument delim = that allows you specify the delimter you wantvroom()
id argument in the vroom() function do?vroom() to import all the mocap files in the challenge folderid = argument in the vroom() function.ID that only contains the ID part from the filenamestr_extract() and str_remove()pattern = argument that must be a regular expressionmutate() call