Re: [R] Aggregating multiple columns

2009-03-19 Thread Gabor Grothendieck
Try this: coef2 <- function(i) cov(x[i,"order"], x[i, "y"]) / var(x[i, "order"]) tapply(1:nrow(x), x$subject, coef2) On Thu, Mar 19, 2009 at 5:41 PM, Adam D. I. Kramer wrote: > Dear colleagues, > >        Consider the following data frame: > > x <- data.frame(y=rnorm(100),order=rep(1:10,10),subj

[R] Aggregating multiple columns

2009-03-19 Thread Adam D. I. Kramer
Dear colleagues, Consider the following data frame: x <- data.frame(y=rnorm(100),order=rep(1:10,10),subject=rep(1:10,each=10)) ...it is my goal to aggregate x to compute a linear effect of order for each subject. So, ideally, result would be a vector containing a single number f