Re: [R] Averaging across rows & columns

From: Silvia Lomascolo <slomascolo_at_zoo.ufl.edu>
Date: Thu, 07 Jun 2007 13:44:57 -0700 (PDT)

michael watson (IAH-C) wrote:
>
> Check out rowMeans to average over replicate columns first, ie:
>
> means <- data.frame(t1=rowMeans(a[,1:3]),
> t2=rowMeans(a[,4:6]),
> etc)
>
> Then, if you want to aggregate every 14 rows:
>
> aggregate(means, by=list(rows=rep(1:(nrow(means)/14), each=14)), mean)
>
> Or something...
>
> YES! This seems to work. Thank you!
>
> -----Original Message-----
> From: r-help-bounces_at_stat.math.ethz.ch on behalf of Silvia Lomascolo
> Sent: Thu 07/06/2007 8:26 PM
> To: r-help_at_stat.math.ethz.ch
> Subject: [R] Averaging across rows & columns
>
>
> I use Windows, R version 2.4.1.
>
> I have a dataset in which columns 1-3 are replicates, 4-6, are replicates,
> etc. I need to calculate an average for every set of replicates (columns
> 1-3, 4-6, 7-9, etc.) AND each set of replicates should be averaged every
> 14
> rows (for more detail, to measure fruit color using a spectrometer, I
> recorded three readings per fruit -replicates- that I need to average to
> get
> one reading per fruit; each row is a point in the light spectrum and I
> need
> to calculate an average reading every 5nm -14 rows- for each fruit).
>
> Someone proposed to another user who wanted an avg across columns to do
>
> a <- matrix(rnorm(360),nr=10)
> b <- rep(1:12,each=3)
> avgmat <- aggregate(a,by=list(b))
>
> I tried doing this to get started with the columns first but it asks for
> an
> argument FUN that has no default. The help for aggregate isn't helping me
> much (a new R user) to discover what value to give to FUN -'average'
> doesn't
> seem to exist, and 'sum' (whatever it is supposed to sum) gives an error
> saying that arguments should have the same length-
>
> Any help will be much appreciated!
> Silvia.
> --
> View this message in context:
> http://www.nabble.com/Averaging-across-rows---columns-tf3885900.html#a11014649
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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_stat.math.ethz.ch 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.
>
>

-- 
View this message in context: http://www.nabble.com/Averaging-across-rows---columns-tf3885900.html#a11015925
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_stat.math.ethz.ch 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 Thu 07 Jun 2007 - 20:49:10 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 Thu 07 Jun 2007 - 22:31:41 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.