Helena
Helena

Reputation: 217

How to read multiple tables from different directory in R?

I have a list of files under 12 different folders, each file has the same name. For example, under folder_A there is a file called quant.txt, under folder_B there is also a file called quant.txt, and so on for other folders. All of these 12 folders are under the same directory.

How do I read/import the list of files from those 12 folders? Maybe something like lapply or list.files?

Upvotes: 1

Views: 185

Answers (1)

Marcus
Marcus

Reputation: 3646

You can replace the the read function but I'm just going to use readLines as a surrogate.

quantData <- purrr::map(list.dirs(), ~readLines(file.path(.x, "quant.txt"))

This iterates through your list of folders, reading the "quant.txt" from each

Upvotes: 1

Related Questions