2

应该是一个简单的任务,但我到目前为止无法找到如何。

样本数据:

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)
4

1 回答 1

8

@Andrie 答案的更简洁版本,因为 XLConnect API 是矢量化的:

wb <- loadWorkbook("var1.xlsx", create = TRUE)
createSheet(wb, names(var1))
writeWorksheet(wb, var1, names(var1),header=FALSE)
saveWorkbook(wb)
于 2012-09-04T06:59:43.140 回答