将数据框列表写入多个Excel文件

时间:2019-07-01 06:57:55

标签: r excel list dataframe lapply

我有一个数据框列表。方便命名:

list.df

和作为数据帧的对象就是这样:

list.df[[1]]  
list.df[[2]]  
list.df[[3]]

我正在尝试使用lapply将每个list.df对象写入单独的Excel工作表。

我无法使用xlsx库,因为我的工作场所禁用了Java的所有功能... 所以我一直在尝试write_xlsx。

我尝试了以下操作:

lapply(names(list.df), 
              function (x) write_xlsx(list.df[[x]], file=paste(x, "xlsx", sep=".")))

但是什么也没发生。

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:3)

对于write_xlsx中的writexl,没有file参数。这是path参数

library(writexl)
lapply(names(list.df), 
          function (x) write_xlsx(list.df[[x]], path=paste(x, "xlsx", sep=".")))

-具有文件的输出目录

enter image description here

数据

list.df <-  list(A = structure(list(X1 = c("a", "d", "g", "j"), X2 = 1:4, 
    X3 = c("b", "e", "h", "k"), X4 = c("c", "f", "i", "l")),
  class = "data.frame", row.names = c(NA, 
-4L)), B = structure(list(X1 = c("a", "d", "g", "j"), X2 = c(1L, 
2L, 2L, 3L), X3 = c("b", "e", "h", "k"), X4 = c("c", "f", "i", 
"l")), class = "data.frame", row.names = c(NA, -4L)), C = structure(list(
    X1 = c("a", "d", "g", "j"), X2 = 1:4, X3 = c("b", "e", "h", 
    "k"), X4 = c("c", "f", "i", "l")), class = "data.frame", row.names = c(NA, 
-4L)))

答案 1 :(得分:2)

我认为这可能对您有帮助

false