Home > Blockchain >  How to quickly export multiple files from RStudio
How to quickly export multiple files from RStudio

Time:12-13

I'd like to know, how can I export subsets of a dataframe in R in an automated way? I am currently using this manual method, where I retype 'a' and 'file_name' values for every file I want to save:

data <- MS[grepl('a', MS$name),] 
write.xlsx(data, 'file_path/file_name')

Any help would be very much appreciated.

CodePudding user response:

I would try something like this:

lijst <- c('a','b','c') # list of the values you type for 'a'

for(a in lijst){
   filename <- paste0('file_path/',a,'.xlsx')
   data <- MS[grepl(a, MS$name),] 
   write.xlsx(data, filename)
   } 
  • Related