Create array of for loop results

Hello,

I'm loading 20 files into R using the below script (they're matrices of 500 x 500). I would like create an array of all the loaded files. is there a way I can have R do it automatically?

##Read files names
filenames <- list.files(path="/Users/dana........")

###Load all files
for(i in filenames){
  filepath <- file.path("/Users/dana........", paste(i))
  assign(i, read.delim(filepath,
                       colClasses=c(rep("numeric",500)),
                       header = FALSE,
                       sep = ";"))
}

##Read files names
filenames <- list.files(path="/Users/dana........")

###Load all files
my_list_of_results <- lappy(filenames,
                             function(i){
                             read.delim( file.path("/Users/dana........", paste(i)),
                                         colClasses=c(rep("numeric",500)),
                                         header = FALSE,
                                         sep = ";")})
1 Like

Perfect, thank you so much!

This topic was automatically closed 7 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.