We split the data frame column wise to export it to excel file. e.g
userid <- rep(1:2,times=4)
data1 <- replicate(8 , paste( sample(letters , 3 ) , collapse = "" ) )
data2 <- sample(10,8)
df <- data.frame( userid , data1 , data2 )
spt3 <- split( df , f = df$userid )
# Split on userid
out <- split( df , f = df$userid )
#$`1`
# userid data1 data2
#1 1 gjn 3
#3 1 yqp 1
#5 1 rjs 6
#7 1 jtw 5
#$`2`
# userid data1 data2
#2 2 xfv 4
#4 2 bfe 10
#6 2 mrx 2
#8 2 fqd 9
now we want to export it to different excel (.xlsx) file
lapply(names(spt3), function(x) {write.table(spt3[[x]], file = paste("solid", x, sep = ""))})
This works for table output but not for excel file as output.I want different excel file for every split output. For instance , spt3[[1]], an excel file as output and similarly for spt3[[2]].
Please note
Thanks for suggestions. But I want (. Xlsx )file not csv. E.g output should be like this in mentioned path output1. Xlsx output2. Xlsx . Also diffeent excel files not different sheets of a single excel file .