Simplified example is:
data<-data.frame(rnorm(10),rbinom(10,1,prob=.7))
sdata<-split(data[,1],data[,2])
ret <- lapply(sdata,mean)
I make data column and factor column. I come from SQL language and solve an,y task with grouping pattern.
lapply(sdata,mean)
is:
class(ret)
[1] "list"
str(ret)
List of 2
$ 0: num -0.146
$ 1: num -0.0572
How can I make data frame again from list?
Are there limitation to factor type? Factor become "name" of list elements and I afraid to lose data/precision when convert from name bask to actual data in data frame.
Is there better way to process partitioned/grouped data then split/lapply?
PS Fill free to correct question wording. I have little experience with R to write professionally.
@MLavoie ret <- data.frame(lapply(sdata,mean))
gives me:
> dim(ret)
[1] 1 2
I expect 2x1.
@David Arenburg function application in lapply
on result from sapply
receive not only single column - but all and not only single row - but all within group. This approach may lead to performance degradation but allow any processing logic.
aggregate
and data.table
work on individual column in each group if I understand properly.