假设我们有一个名为
list_data
的数据框列表。
我们的目标是为每个
.xlsx
编写一个单独的 openxlsx::write.xlsx()
文件,其中每个文件都有两个以 District
中的 data.frames 命名的子表(也称为选项卡)(在本例中,这些名称是list_data
和 one
)。因为某些 two
仅包含在
District
或 one
中,对于此类 two
,其中一个子表将为空,这是可以的。文件名可以是 District
的名称。
我尝试了以下方法但没有成功。这在 R 中可能吗?District
library(tidyverse)
library(openxlsx)
list_data<- list(one= data.frame(District=LETTERS[1:3], V1 = 1:3),
two= data.frame(District=LETTERS[3:8], V7 = 3:8, V3=8:3))
lapply(list_dat,\(j)
group_by(j,District) %>%
write.xlsx(file =paste0(j$District,".xlsx"), sheetName = ???)) # Not sure how to add subsheet names here