应该是一项简单的任务,但我到目前为止还无法找到。
示例数据:
var1 <- list('2003' = 1:3, '2004' = c(4:3), '2005' = c(6,4,1), '2006' = 1:4 )
代码不成功:
library("XLConnect")
wb <- loadWorkbook("var1.xlsx", create = TRUE)
wb <- lapply(var1, function(x) {createSheet(wb, name = x)})
saveWorkbook(wb)
答案 0 :(得分:8)
@ Andrie答案的更简洁版本,因为XLConnect API是矢量化的:
wb <- loadWorkbook("var1.xlsx", create = TRUE)
createSheet(wb, names(var1))
writeWorksheet(wb, var1, names(var1),header=FALSE)
saveWorkbook(wb)