Re: [R] Help on aggregate method

2010-06-01 Thread Stella Pachidi
Dear Erik, Thank you very much. Indeed ave did the same job amazingly fast! I did not know the function before. Many thanks to all R experts who answer to this mailing list, it's amazing how much help you offer to the newbies :) Kind regards, Stella On Tue, Jun 1, 2010 at 6:11 PM, Erik Iverson

Re: [R] Help on aggregate method

2010-06-01 Thread Erik Iverson
Stella Pachidi wrote: Dear Erik and R experts, Thank you for the fast response! I include an example with the ChickWeight dataset: ap.dat <- ChickWeight matchMeanEx <- function(ind,dataTable,aggrTable) { index <- which((aggrTable[,1]==dataTable[["Diet"]][ind]) & (aggrTable[,2]==dataTabl

Re: [R] Help on aggregate method

2010-06-01 Thread Stella Pachidi
Dear Erik and R experts, Thank you for the fast response! I include an example with the ChickWeight dataset: ap.dat <- ChickWeight matchMeanEx <- function(ind,dataTable,aggrTable) { index <- which((aggrTable[,1]==dataTable[["Diet"]][ind]) & (aggrTable[,2]==dataTable[["Chick"]][ind])) as.n

Re: [R] Help on aggregate method

2010-06-01 Thread Joris Meys
Take a look at ?split (and unsplit) eg: Dur <- rnorm(100) Attr1=rep(c("A","B"),each=50) Attr2=rep(c("A","B"),times=50) ap.dat <-data.frame(Attr1,Attr2,Dur) split.fact <- paste(ap.dat$Attr1,ap.dat$Attr2) ap.list <-split(ap.dat,split.fact) ap.mean <-lapply(ap.list,function(x){ x$meanDur=re

Re: [R] Help on aggregate method

2010-06-01 Thread Erik Iverson
It's easiest for us to help if you give us a reproducible example. We don't have your datasets (ap.dat), so we can't run your code below. It's easy to create sample data with the random number generators in R, or use ?dput to give us a sample of your actual data.frame. I would guess your prob

[R] Help on aggregate method

2010-06-01 Thread Stella Pachidi
Dear R experts, I would really appreciate if you had an idea on how to use more efficiently the aggregate method: More specifically, I would like to calculate the mean of certain values on a data frame,  grouped by various attributes, and then create a new column in the data frame that will have