Re: [R] Noobie question on aggregate tapply and by

2010-04-26 Thread Henrique Dallazuanna
Try this: aggregate(DF[c('data', 'data2')], DF[ 'years'], FUN = sum, na.rm = TRUE) aggregate(DF[c('data', 'data2')], list(as.character(factor(DF[, 'years'], labels = c('5-7', '5-7', '5-7', 8, FUN = sum, na.rm = TRUE) On Sun, Apr 25, 2010 at 3:29 AM, steven mosher wrote: > I have a 43MB dataf

Re: [R] Noobie question on aggregate tapply and by

2010-04-25 Thread steven mosher
thx I was struggling with the DF[,3:4] part of it On Sun, Apr 25, 2010 at 10:47 AM, John Kane wrote: > Here's one way with aggregate() > > library(car) # You probably will need to install it. > > aggregate(DF[,3-4], by=list(years), mean,na.rm=TRUE) > > recode(x, "c(1,2)='A'; else='B'") > > DF$

Re: [R] Noobie question on aggregate tapply and by

2010-04-25 Thread John Kane
Here's one way with aggregate() library(car) # You probably will need to install it. aggregate(DF[,3-4], by=list(years), mean,na.rm=TRUE) recode(x, "c(1,2)='A'; else='B'") DF$years <- recode(DF$years, "c(5,6,7)= '5-7'") DF You may also want to have a look at the reshape and plyr packages.

Re: [R] Noobie question on aggregate tapply and by

2010-04-25 Thread steven mosher
Thanks I'll try that, still need to understand how the other functions work.. just to satisfy myself..thanks again On Sun, Apr 25, 2010 at 12:06 AM, Tal Galili wrote: > Here is one solution for your question: > > mean.data <- with(DF, tapply(data, years, mean, na.rm = T)) > mean.data2 <- with(DF

Re: [R] Noobie question on aggregate tapply and by

2010-04-25 Thread Tal Galili
Here is one solution for your question: mean.data <- with(DF, tapply(data, years, mean, na.rm = T)) mean.data2 <- with(DF, tapply(data2, years, mean, na.rm = T)) cbind(mean.data , mean.data2) Another one would be for you to read about the package plyr (which is better for this job, actually) An