问题
Can somebody help me on how to export multiple data frames to the same xlsx-file in R?
I know how to do it excel, but getting an out of memory error after exporting few files. So I do not want to touch excel.
回答1:
write.table(df1, "test.csv", row.names = F)
write.table(df2, "test.csv", append = T, col.names = F, row.names = F)
EDIT:
To write to two different sheets in an xlsx-file:
library(openxlsx)
wb <- createWorkbook()
addWorksheet(wb, "Sheet 1")
addWorksheet(wb, "Sheet 2")
writeData(wb, 1, df1)
writeData(wb, 2, df2)
saveWorkbook(wb, file = "test.xlsx", overwrite = TRUE)
来源:https://stackoverflow.com/questions/46569798/how-to-export-multiple-data-frames-to-same-xlsx-file-with-r