I'd like to calculate the geometric mean of long vectors of numbers, but I often seem to be limited by the size of numbers that R can store. To calculate a geometric mean, one has to find the product of all the numbers, which can be a gigantic number if the vector and/or the numbers are sufficiently large, and R seems to run out of space for it, e.g.:
> prod(sample(3,1000,replace=T))
[1] 2.09439e+265
is ok, but
> prod(sample(10,1000,replace=T))
[1] Inf
is not.
Is there a workaround, or do have to either A) settle for an approximation for the geometric mean (mean(x) - var(x)/2
being a widely-cited but rather terrible approximation), or B) export the data and use some other software such as Mathematica to do the job?
Many thanks