0

So I have files that are in the same format with the same prefix "01_qc-..." and these files are also in different folders all labeled "Data...".

How do I read in all of the files simply into one dataframe in R?

starski
  • 141
  • 6
  • 1
    `list.files()` has a `recursive` argument which if set to `TRUE` searches subdirectories. Set the pattern to `"^01_qc-"` and `full.names` to `TRUE` to find files with that format and return their complete path. You can then apply a function such as `read.table` to that list and `rbind` the results into a single dataframe. – Paul Stafford Allen Nov 29 '22 at 11:17
  • Thank you for your input @PaulStaffordAllen, since these datasets are very large, is there a way in `lapply()` to only select certain columns from the datasets while reading in the data? – starski Nov 29 '22 at 12:05
  • @starski, [this](https://stackoverflow.com/a/63867118/18289387) answer uses `map_df` and not `lapply`, but maybe it would be of use. – shaun_m Nov 29 '22 at 12:21
  • It's probably better to preselect the columns when reading the data files in - can you give example formats and column specifications? – Paul Stafford Allen Nov 29 '22 at 12:22
  • I actually used `fread` in `lapply` and then `rbindlist` and from there I selected the columns I needed, that did the trick – starski Nov 29 '22 at 12:38

0 Answers0