将数据框列表写入多个Excel文件 [英] write list of dataframes to multiple excel files

查看:51
本文介绍了将数据框列表写入多个Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a list of dataframes. Conveniently named:

list.df

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

and the objects, which are dataframes, are just this:

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

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

I am trying to use lapply to write each of the list.df objects to a seperate excel sheet.

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

I can't use the xlsx library because my workplace disables everything Java... so I've been trying write_xlsx.

我尝试了以下操作:

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

但是什么也没发生.

任何帮助将不胜感激.

推荐答案

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

For write_xlsx from writexl, there is no file argument. It is the path argument

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

-具有文件的输出目录

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

这篇关于将数据框列表写入多个Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆