Halabi, Anan
2010-Sep-17 16:08 UTC
[R] Matrix- create mean/min/max/stdev on column of matrix or rows?
I made simulation with Weibull and create Matrix, How can I create mean/min/max/stdev on column or rows of matrix?, Thanks,
Dennis Murphy
2010-Sep-17 17:17 UTC
[R] Matrix- create mean/min/max/stdev on column of matrix or rows?
Hi: Here's a simple example that you can tune to your needs: m <- matrix(rpois(100, 10), nrow = 10) # Function to compute summary statistics: f <- function(x) c(min = min(x), med = median(x), mean = mean(x), max max(x)) # Apply to rows (index 1) apply(m, 1, f) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] min 5.0 7.0 5.0 6.0 5.0 5.0 8.0 5.0 2.0 6.0 med 11.5 9.5 10.0 9.5 9.0 8.0 10.0 10.0 6.0 10.0 mean 11.1 9.8 10.4 10.3 9.6 7.6 10.5 9.3 6.6 9.8 max 15.0 14.0 17.0 15.0 17.0 10.0 14.0 14.0 16.0 12.0 # Apply to columns (index 2) apply(m, 2, f) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] min 3.0 6.0 5.0 6.0 2.0 5.0 5.0 5.0 8.0 6.0 med 9.0 9.5 11.0 9.5 8.5 9.5 9.0 6.0 10.5 10.0 mean 8.6 9.6 10.8 9.8 8.5 9.7 9.7 7.8 11.0 9.5 max 12.0 15.0 15.0 17.0 14.0 15.0 17.0 14.0 16.0 14.0 HTH, Dennis On Fri, Sep 17, 2010 at 9:08 AM, Halabi, Anan <anan.halabi@hp.com> wrote:> I made simulation with Weibull and create Matrix, > How can I create mean/min/max/stdev on column or rows of matrix?, > Thanks, > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
Henrique Dallazuanna
2010-Sep-18 01:41 UTC
[R] Matrix- create mean/min/max/stdev on column of matrix or rows?
Try this: apply(m, 1, summary) # 1 or 2 On Fri, Sep 17, 2010 at 1:08 PM, Halabi, Anan <anan.halabi@hp.com> wrote:> I made simulation with Weibull and create Matrix, > How can I create mean/min/max/stdev on column or rows of matrix?, > Thanks, > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]