0

I have a dataset df

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

I want to export as xlsx files each of them seperated filtered column

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

output of ccc.xlsx

aa1  bb1  ccc
aa2  bb2  ccc

output of ddd.xlsx

aa3  bb3  ddd
aa4  bb4  ddd

output of eee.xls

aa5  bb5  eee

Thanks

ersan
  • 393
  • 1
  • 9

1 Answers1

1

Something like that should work:

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

Data

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