Never mind, I find a generic solution:
require(reshape)
melted<-melt(dataframe, id=c("id","f1","f2"))
averaged=cast(melted,id+f1~variable,mean)
which collapses away "f2", and it's easy to generalize this to collapse
any factors.
Thanks anyway
Gordon
On 4/25/11 6:14 AM, Kenneth Roy Cabrera Torre
Hi Junquian:
I try your code (there is a typo, I believe)
a<-rnorm(6)
b<-rnorm(9)
f1<-c("x1","x2","x3")
f2<-c("y1","y2")
id<-c(1:6)
a_df<-data.frame(cbind(id,f1,"y1",a))
id<-c(1:9)
b_df<-data.frame(cbind(id,f1,"y2",b))
But I don't understand the "nested" databases.
I see that both have f1 variab
I have two nested data frames:
a<-rnorm(6)
b<-rnorm(9)
f1<-c("x1","x2","x3"))
f2<-c("y1","y2")
id<-c(1:6)
a_df<-data.frame(cbind(id,f1,"y1",a))
id<-c(1:9)
b_df<-data.frame(cbind(id,f1,"y2",b))
I want to preserve id and f1, but want to collapse f2 and take the
corresponding mean values of a and b.
3 matches
Mail list logo