Combining .csv files in R

Hi everyone

So I have a script that works off .csv files for data that I need to analyze for my PhD. The problem I am having is that I have 1080 .csv files that I need to combine. However, I need to only combine 3 at a time due to the nature of the analysis that I'm doing.

Can anyone help me with a smoother way to do this than creating dataframes for each file and just combining the dataframes?

Thank you to anyone that is willing to help.

You can combine csv files like this:

library(readr)
library(purrr)

file_list <- list.files(path = "filepath", pattern = "namepattern", full.names = TRUE)
combined <- map_dfr(file_list, read_csv)

The path is relative to the current directory. The pattern will depend on how your files are named.

Check ?list.files for more help.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Thank you for replying, my file names are named all the same thing except the last three digits, which are their distinguishing factor: _001 and goes to _180.

Is it possible to create a loop to be able to read these files and then save them separately from each other (3 combined) without having to write the script out each time stating the _001 etc.? I want to create a separate folder with the combined .csv files so the files should go from _001 to _060 (instead of the _001 to _180).

So the "new" _001 will have the "old" _001 to _003 within it and the "new" _002 will have the "old" _004 to _006 (as the 3 files are being combined into one) and ending with the "new" _060 having the old _178 to _180 within it.