Re: [R] How to take the ave of two rows in a data frame

From: John Kane <jrkrideau_at_yahoo.ca>
Date: Fri, 30 Nov 2007 10:37:40 -0500 (EST)


Try the reshape package

This should do what you want.



library(reshape)
df1 <- melt(mydata, id=c("ID"),
measured=c("a1","a2","a3")) ; df1
stats <- cast(df1, ID ~ variable , mean) ; stats

> > Dear list,
> > I have a data frame like:
> >
> > > log2.ratios[1:3,1:4]
> > ID a1 a2

>           a3

> > 1 GS1-232B23 -0.0207500 0.17553833
> 0.21939333
> > 2 RP11-82D16 -0.1896667 0.02645167
> -0.03112333
> > 3 RP11-62M23 -0.1761700 0.08214500
> -0.04877000
> > 4 RP11-62M23 0.2761700 -0.15214500
> -0.05877000

> >
> 
> the 3rd and 4th rows are of the same ID, I would
> like to take the avarage of
> these
> two rows and get the data frame to:
> 
>         ID                  a1             a2       
>      a3
> 1 GS1-232B23      -0.0207500 0.17553833  0.21939333
> 2 RP11-82D16      -0.1896667 0.02645167 -0.03112333
> 3 RP11-62M23      -0.05         -0.035          
> 0.094135
> 
> Can anyone suggest how to deal with this (to take
> the ave of two rows of the
> same ID ) more quickly?
> 
> Thanks a bunch!
> 
> Allen
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 30 Nov 2007 - 15:41:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 30 Nov 2007 - 16:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.