Export data to a list as sheets in an Excel file

It should be a simple task, but I still can not find it.

Sample data:

var1 <- list('2003' = 1:3, '2004' = c(4:3), '2005' = c(6,4,1), '2006' = 1:4 )

Bad code:

library("XLConnect")
wb <- loadWorkbook("var1.xlsx", create = TRUE)
wb <- lapply(var1, function(x) {createSheet(wb, name = x)})
saveWorkbook(wb)
+2
source share
1 answer

A more concise @Andrie answer, as the XLConnect API is vectorized:

wb <- loadWorkbook("var1.xlsx", create = TRUE)
createSheet(wb, names(var1))
writeWorksheet(wb, var1, names(var1),header=FALSE)
saveWorkbook(wb)
+8
source

All Articles