I have 2 data frames that I would like to export to Excel, with each dataframe on a different worksheet, and to title each sheet.
I have tried the following with write.xlsx
.
Here is the list of my 2 data frames followed by the title I would like to give them in the new Excel workbook:
list_of_datasets <- list(pivot.diagnosis, stat.pivot.quarter)
wk.title <- c("9-STD Durations", "10-STD Clinical Categories")
This is the loop I have tried:
for (i in length(list_of_datasets)) {
write.xlsx(list_of_datasets[i], file = "Trial.xlsx",
sheetName = wk.title[i],
append = TRUE)
}
PROBLEM: This only outputs the last data frame (i.e. stat.pivot.quarter
) to the Trial.xlsx spreadsheet. Append = TRUE
is there, so I would think it would append with each iteration of the loop, but it's not. It seems like append = T
isn't working
Any leads appreciated!