geometric_mean | R Documentation |
Calculate the geometric mean of a vector. This function is valid for non-negative, non-NA containing vectors.
geometric_mean(x, zero_propagate = FALSE, ignore_zero = TRUE)
x |
numeric vector of non-negative values |
zero_propagate |
logical. Should zeros be included in the calculation. Default FALSE. |
ignore_zero |
logical. Should zero values be ignored in the calculation of the mean? Default TRUE. |
geometric mean of the vector
# Normal case
geometric_mean(c(2, 5, 95, 5))
# Default ignores 0s entirely
geometric_mean(c(2, 5, 95, 5, 0, 0, 0, 0))
# Ignore zero = FALSE -- zero is used in mean calculation
geometric_mean(c(2, 5, 95, 5, 0, 0, 0, 0), ignore_zero = FALSE)
# Case with NA -- Returns NA
geometric_mean(c(NA, 1, 2, 3))
# Case with 0 propagation -- Returns 0
geometric_mean(c(0, 1, 2, 3), zero_propagate = TRUE)
# Case with negative -- Returns NaN
geometric_mean(c(-1, 2, 3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.