I've got a list of 24 dataframes and I'm wondering if there's an easy way to export each element to it's own excel file from R, preferably using the name of the list element in the excel file's title?
I know I can do write.xlsx(listofdfs, "newexcelfilename.xlsx") and it will put each element into it's own worksheet within the file, but in my case I'll eventually need to email these files separately so it's best if I can get them into their own individual excel files. Thanks in advance!
CodePudding user response:
You may use any of the apply function in base R. For example, using Map
-
Map(openxlsx::write.xlsx, listofdfs, paste0(names(listofdfs), '.xlsx'))
Also with purrr::imap
-
purrr::imap(listofdfs, ~openxlsx::write.xlsx(.x, paste0(.y, '.xlsx')))