gmean: Geometric mean

gmean_sumR Documentation

Geometric mean

Description

Computes the geometric mean(s) of a numeric vector, matrix or data.frame

Usage

gmean_sum(x, margin = NULL)

gmean(x, margin = NULL)

Arguments

x

matrix or data.frame with numeric entries

margin

a vector giving the subscripts which the function will be applied over, 1 indicates rows, 2 indicates columns, 3 indicates all values.

Details

gmean_sum calculates the totals based on geometric means while gmean calculates geometric means on rows (margin = 1), on columns (margin = 2), or on all values (margin = 3)

Value

geometric means (if gmean is used) or totals (if gmean_sum is used)

Author(s)

Matthias Templ

Examples

data("precipitation")
gmean_sum(precipitation)
gmean_sum(precipitation, margin = 2)
gmean_sum(precipitation, margin = 1)
gmean_sum(precipitation, margin = 3)
addmargins(precipitation)
addmargins(precipitation, FUN = gmean_sum)
addmargins(precipitation, FUN = mean)
addmargins(precipitation, FUN = gmean)

data("arcticLake", package = "robCompositions")
gmean(arcticLake$sand)
gmean(as.numeric(arcticLake[1, ]))
gmean(arcticLake)
gmean(arcticLake, margin = 1)
gmean(arcticLake, margin = 2)
gmean(arcticLake, margin = 3)

robCompositions documentation built on Aug. 25, 2023, 5:13 p.m.