[R] Averaging across rows & columns

Silvia Lomascolo slomascolo at zoo.ufl.edu
Thu Jun 7 21:26:40 CEST 2007


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.



More information about the R-help mailing list