Re: [R] Geometric mean of rows in matrix

2009-08-20 Thread David Winsemius
On Aug 20, 2009, at 2:22 PM, Edward Chen wrote: Is there a function or an easier way to computer geometric means of each rows in a nxn matrix and spit out in an 1xn matrix ? > xx <- matrix(10+rnorm(100), 10) > apply(xx, 1, function(x) exp(mean(log(x))) ) [1] 10.084711 10.034054 9.622909

Re: [R] Geometric mean of rows in matrix

2009-08-20 Thread Benilton Carvalho
set.seed(1) x <- matrix(runif(1000), 100) system.time(tmp1 <- exp(rowMeans(log(x system.time(tmp2 <- apply(x, 1, function(y) prod(y)^(1/length(y all.equal(tmp1, tmp2) ## tmp1 is more robust, btw On Aug 20, 2009, at 3:22 PM, Edward Chen wrote: Is there a function or an easier way to comp

[R] Geometric mean of rows in matrix

2009-08-20 Thread Edward Chen
Is there a function or an easier way to computer geometric means of each rows in a nxn matrix and spit out in an 1xn matrix ? -- Edward Chen [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman