[R] quantiles on rows of a matrix
Jim Bouldin
jrbouldin at ucdavis.edu
Thu Jul 8 00:52:22 CEST 2010
I'm trying to obtain the mean of the middle 95% of the values from each row
of a matrix (that is, the highest and lowest 2.5% of values in each row
are removed before calculating the mean). I am having all sorts of
problems with this; for example the command:
apply(matrix1,1,function(x) quantile(c(.05,.90),na.rm=T))
returns the exact same quantile values for each row, which is clearly
wrong. But even if the values were right, I'm not sure how I would then
translate those quantile values into another apply function to get the
mean, since they differ from row to row.
I also tried:
apply(matrix,1,mean,na.rm=T,trim=.05))
and the trim argument was simply ignored
Stumped. Any help appreciated. Thanks.
Jim Bouldin, PhD
Research Ecologist
Department of Plant Sciences, UC Davis
Davis CA, 95616
530-554-1740
More information about the R-help
mailing list