I would like to import some xlsx files into rstudio. These files are all in the same folder, but there are also some other xlsx files in there, that I am not interested in:
I would like to import all four "Alles_...." files building a single dataframe (called for example All) containing all this data. And I would like the function to ignore every other file not starting with "Alles_"
Which function can I use?
Thank you in advance!
Firstly, I would set the working directory with setwd()
, and then:
dir()[grepl('Alles', ignore.case = T, dir())] -> files
do.call('rbind', lapply(files, function(file) openxlsx::read.xlsx(file)))
In case you want the second sheet:
do.call('rbind', lapply(files, function(file) openxlsx::read.xlsx(file, sheet = 2)))