1

I am new to R. I have several txt. files in several sub-folders under one folder. The structuer of the txt files are the same. I would like to iterate the files for each sub-folder and generate a signle file for the whole folder. I coded as follow:

parent.folder <-"C:/.../18_0101"  # Folder containing sub-folders
sub.folders <- list.dirs(parent.folder, recursive=TRUE)[-1] #
Sub-folders r.scripts <- file.path(sub.folders) HR_2018 <- list() for
(j in seq_along(r.scripts)) {   HR_2018[[j]] <- dir(r.scripts[j],"\\.txt$")}

When I checked HR_2018[[1]], I found only the list of .txt files under the sub-folder. From there, I would like to analyze the files under each sub-folder. And then I would like to iterate the same process for other sub-folders under the folder and generate a single file. Anyone help me?

Phil
  • 7,287
  • 3
  • 36
  • 66
Heiwa
  • 41
  • 4
  • 1
    Does this answer your question? [How do you read multiple .txt files into R?](https://stackoverflow.com/questions/3397885/how-do-you-read-multiple-txt-files-into-r) – Adam Quek Jun 20 '22 at 05:41

0 Answers0