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 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/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@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.

Reply via email to