0

I used this R code to read in 800 similar CSV files from one folder. All the Column headers are the same. The files name contain the ID of the data e.g. 2.csv, 5.csv, ... 5691.csv , 5780.csv, etc.

PSnow_dat <- list.files(pattern = "*.csv") %>% 
  map_df(~fread(.))

the scrip combines all files into one dataframe, does it read the data in the correct order?

I accually want to have the names of the file ( the ID of the data) as one column in my dataframe! Can anyone help?

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Check out the id arguments for `dplyr::bind_rows()` or `data.table::rbindlist()`--sounds like they do what you are looking for if you keep the 800 csv's in list format to begin with. – Andrew Mar 05 '20 at 17:43
  • You may need to use `sapply()` to retain names. i forget if `map()` / `lapply()` do when importing. – Andrew Mar 05 '20 at 17:44

0 Answers0