In R, find geometric mean of monthly data converted into quarterly data Looking to find geometric mean of monthly data that's been converted into quarterly data. I've tried several methods but only provide simple arithmetic  mean as shown below. Thanks.
monthly <- ts(mydata,start=c(1960,1),frequency=12)
quarterly <- aggregate(monthly, nfrequency=4,mean) ---need geometric mean

This looks promising but unable to mimic the above simple arithmetic mean which considers the monthly to quarterly data transformation:
# Function to calculate the geometric mean
geometricMean &lt;- function(array){
 if(!is.numeric(array)){
 stop(&quot;Passed argument must be an array. Consider using sapply for data frames.&quot;)
 }
 if(any(array&lt;0)){
 stop(&quot;All values must be greater than zero. If you are attempting to
 apply this function to rates, convert to +1 format. For example,
 5% becomes 1.05 and -20% becomes .8.&quot;)
 }
 prod(array)^(1/length(array))
}

The data has been transformed into percentage change rates (month_12 - month_11 / month_11)
 A: The easiest thing to is to convert your data into logarithms and then you can compute the geometric mean by taking the exponent of the sum.
I.e., 
$
\begin{bmatrix}
    x_{i}       & x_{i+1} & x_{1+2} & \dots & x_{n} \\
\end{bmatrix} \to
\begin{bmatrix}
    Ln [x_{i}] & Ln[x_{i+1}] & Ln[x_{i+2}] & \dots  & Ln[x_{n}] \\
\end{bmatrix}
$
$\text{Geometric mean} +1 = (\prod_i^n (1+x))^{1/n}  = exp\left[ \frac{\sum_i^n ln[x_i]}{ n} \right] = exp\left[\mu_{ln(x)} \right]$
where: $\mu_{ln(x)}$ is the simple arithmetic mean of the logarithm of x.
A: The geometric mean is undefined when any of the data are negative. This has nothing to do with whether the data are monthly or quarterly, nor with any problems with R or your code. 
The solution to this problem seems to be right in the code that you quote, in particular:

All values must be greater than zero. If you are attempting to
   apply this function to rates, convert to +1 format. For example,
   5% becomes 1.05 and -20% becomes .8

Have you tried this?
