I have a list of dataframes that I would like to split based on a column, in that case the cluster column.
d1 <- data.frame(y1=c(1,2,3), cluster=c(1,2,6))
d2 <- data.frame(y1=c(3,2,1), cluster=c(6,2,4))
my.list <- list(d1, d2)
Using
lapply(my.list , function(x) split(x, x$cluster)) returns the splitted dataframes as sublists. Is it possible to split the dataframes and create new dataframes as separate list entries?
The desired output would be something like this:
my.list2 <- list(df1_cl1 , df1_cl2m df1_cl6, df2_cl6, df2_cl2, df2_cl4 )