I am trying to save dataframes into distinct spreadsheets within an .xlsx document:
library(xlsx)
df1 <- data.frame(a=c("a", "b", "c"), b=c(3,4,5))
df2 <- data.frame(r=c(1,2,3), d=c("a", "b", "c"))
# append into corresponding spreadsheet
write.xlsx2(as.data.frame(df1),
"path/dummy.xlsx",
sheetName = "TestSheet1",
col.names = T,
row.names = F,
append = F)
write.xlsx2(as.data.frame(df2),
"path/dummy.xlsx",
sheetName = "TestSheet2",
col.names = T,
row.names = F,
append = F)
However, write.xlsx2() remove "TestSheet1":
The idea is to have two distinct spreadsheets for two distinct dataframes, and if possible to append new data into the spreadsheets dataframes while keeping the same spreadsheets.
How could I accomplish this task?
