library("dplyr") geometric.mean <- function(x){ prop <- c(na.omit(x / dplyr::lag(x))) return(exp(mean(log(prop)))) } x <- c(1000, 1000*1.1, 1100*1.2, 1320*0.85) geometric.mean(x)
> geometric.mean(x) [1] 1.039117