Re: [R] Calculate mean/var by ID

2008-09-12 Thread Adaikalavan Ramasamy
--- On Thu, 9/11/08, Adaikalavan Ramasamy <[EMAIL PROTECTED]> wrote: From: Adaikalavan Ramasamy <[EMAIL PROTECTED]> Subject: Re: [R] Calculate mean/var by ID To: "Jorge Ivan Velez" <[EMAIL PROTECTED]> Cc: "liujb" <[EMAIL PROTECTED]>, r-help@r-project.org Da

Re: [R] Calculate mean/var by ID

2008-09-12 Thread Julia Liu
From: Adaikalavan Ramasamy <[EMAIL PROTECTED]> Subject: Re: [R] Calculate mean/var by ID To: "Jorge Ivan Velez" <[EMAIL PROTECTED]> Cc: "liujb" <[EMAIL PROTECTED]>, r-help@r-project.org Date: Thursday, September 11, 2008, 10:28 PM A slight variation of what Jorge

Re: [R] Calculate mean/var by ID

2008-09-11 Thread Adaikalavan Ramasamy
A slight variation of what Jorge has proposed is: f <- function(x) c( mu=mean(x), var=var(x) ) do.call( "rbind", tapply( df$value, df$ID, f ) ) mu var 111 4.33 4.33 138 6.00 4.67 178 5.00 8.00 Regards, Adai Jorge Ivan Velez wrote: Dear J

Re: [R] Calculate mean/var by ID

2008-09-11 Thread Jorge Ivan Velez
Dear Julia, Try also x=read.table(textConnection("IDvalue 111 5 111 6 111 2 178 7 178 3 138 3 138 8 138 7 138 6"),header=TRUE) closeAllConnections() attach(x) do.call(rbind,tapply(value,ID, function(x){ res=c(mean(x,na.rm=TRUE),var(x,na.rm=TRUE)) names(res

Re: [R] Calculate mean/var by ID

2008-09-11 Thread Adam D. I. Kramer
aggregate(value,list(ID=ID),mean) aggregate(value,list(ID=ID),var) --Adam On Thu, 11 Sep 2008, liujb wrote: Hello, I have a data set that looks like this. IDvalue 111 5 111 6 111 2 178 7 178 3 138 3 138 8 138 7 138 6 . . . I'd like to calculate the me

Re: [R] Calculate mean/var by ID

2008-09-11 Thread Henrique Dallazuanna
Try: with(x, sapply(list(mean, var), function(x)tapply(value, ID, x))) On Thu, Sep 11, 2008 at 2:45 PM, liujb <[EMAIL PROTECTED]> wrote: > > Hello, > > I have a data set that looks like this. > IDvalue > 111 5 > 111 6 > 111 2 > 178 7 > 178 3 > 138 3 > 138 8 > 138

[R] Calculate mean/var by ID

2008-09-11 Thread liujb
Hello, I have a data set that looks like this. IDvalue 111 5 111 6 111 2 178 7 178 3 138 3 138 8 138 7 138 6 . . . I'd like to calculate the mean and var for each object identified by the ID. I can in theory just loop through the whole thing..., but is th