Reputation: 1
for(x in unique_seg){
bf <- data.frame(matrix(x,nrow =3,ncol =3))
write.xlsx(bf,'bf.xlsx', sheetname =x, append=True) }
But I see only last loop is returned. How to get all sheets in 1 excel ?
Upvotes: 0
Views: 30
Reputation: 886948
If we want to return the output, create a list
and assign the output to the list
lst1 <- vector('list', length(unique_seg))
names(lst1) <- unique_seg
for(x in unique_seg){
bf <- data.frame(matrix(x,nrow =3,ncol =3))
write.xlsx(bf,'bf.xlsx', sheetname =x, append=TRUE)
lst1[[x]] <- bf
}
Upvotes: 1