geometricMean: Geometric mean

geometricMeanR Documentation

Geometric mean

Description

The geometric mean is the nth root of n products or e to the mean log of x.

Usage

geometricMean(x, ...)

## S4 method for signature 'AsIs'
geometricMean(x)

## S4 method for signature 'matrix'
geometricMean(x, MARGIN = 2L)

## S4 method for signature 'numeric'
geometricMean(x, removeNa = TRUE, zeroPropagate = FALSE)

Arguments

x

Object.

MARGIN

integer(1-2). Dimension where the function will be applied. For a two-dimensional matrix: 1 indicates rows; 2 indicates columns; c(1, 2) indicates rows and columns.

removeNa

logical(1). Remove NA values from calculations.

zeroPropagate

logical(1). Allow propagation of zeroes.

...

Additional arguments.

Details

This function should be fully zero- and NA-tolerant. This calculation is not particularly useful if there are elements that are <= 0 and will return NaN.

Value

numeric.

Note

Updated 2021-10-14.

See Also

Examples

## numeric ====
vec1 <- seq(from = 1L, to = 5L, by = 1L)
print(vec1)
geometricMean(vec1)

vec2 <- vec1^2L
print(vec2)
geometricMean(vec2)

## matrix ====
matrix <- matrix(
    data = c(vec1, vec2),
    ncol = 2L,
    byrow = FALSE
)
print(matrix)
geometricMean(matrix)

acidgenomics/acidbase documentation built on Jan. 26, 2024, 4:26 p.m.