从 table 导出 xlsx 文件作为单独的过滤列

Export xlsx files from table as seperated filtered column

我有一个数据集 df

aa1  bb1  ccc
aa2  bb2  ccc
aa3  bb3  ddd
aa4  bb4  ddd
aa5  bb5  eee

我想导出为 xlsx 文件,每个文件都是单独的过滤列

write.xlsx(df, 'files(ccc,ddd,eee,...).xlsx')

ccc.xlsx

的输出
aa1  bb1  ccc
aa2  bb2  ccc

ddd.xlsx

的输出
aa3  bb3  ddd
aa4  bb4  ddd

eee.xls

的输出
aa5  bb5  eee

谢谢

类似的东西应该可以工作:

files <- unique(df$V3) # Or manually files <- c("ccc", "ddd", "eee")
for (f in files) {
  write.xlsx(df[df$V3 == f, ], paste0(f, ".xlsx"))
}

数据

df <- data.frame(
  V1 = c("aa1", "aa2", "aa3", "aa4", "aa5"), 
  V2 = c("bb1", "bb2", "bb3", "bb4", "bb5"), 
  V3 = c("ccc", "ccc", "ddd", "ddd", "eee")
)