Achal Neupane
Achal Neupane

Reputation: 5719

How to list all the files in 2 or more directories in R?

I want to select all the files(all.files) in three different folders and use a function on those files. So when I use a function or loop to loop over each of all.files, I should be able to get access to those files in their respective directories.How do I achieve this goal? I did something like this, but did not work:

bam.dir <- c("path1/ABAM/","path2/BBAM/","path3/CBAM/")

all.files<-list.files(bam.dir)

Upvotes: 1

Views: 51

Answers (1)

Rorschach
Rorschach

Reputation: 32446

Try

all.files <- Vectorize(list.files)(bam.dir)

This creates a vectorized version of list.files, allowing you to pass a vector of directories as the first argument.

Upvotes: 1

Related Questions