Re: [R] question: ragged array

2011-10-16 Thread Dennis Murphy
Hi: Try this: ratok <- data.frame(Id = rep(1:3, 3:1), value = c(2, 3, 4, 2, 1, 5)) aggregate(value ~ Id, data = ratok, FUN = mean) Id value 1 1 3.0 2 2 1.5 3 3 5.0 aggregate() returns a data frame with the Id variable and mean(value). HTH, Dennis On Sun, Oct 16, 2011 at 6:53 AM, Hel

Re: [R] question: ragged array

2011-10-16 Thread Weidong Gu
if you set parameter simplify=TRUE, it returns a vector of the ragged mean. In your case, mean_rating <- tapply(ratok$value, ratok$project_id , mean,simplify = TRUE) df<-data.frame(ID=dimnames(mean_rating)[[1]], mean=mean_rating) Weidong Gu On Sun, Oct 16, 2011 at 9:53 AM, Helene Schreyer wrot