mpm_mean: Calculate a mean over a list of matrices or CompadreMat...

View source: R/mpm_mean.R

mpm_meanR Documentation

Calculate a mean over a list of matrices or CompadreMat objects

Description

Calculates an element-wise mean over a list of matrices or CompadreMat objects of constant dimension.

The difference between function mat_mean) and (mpm_mean is that mat_mean takes input as a list of matrices (e.g., a list of **A** matrices) while mat_mean takes input as a list of 'CompadreMat' objects and thus calculates the mean matrices for both the **A** matrix and its submatrices (**U**, **F**, **C**).

Usage

mat_mean(x, na.rm = FALSE)

mpm_mean(x, na.rm = FALSE)

Arguments

x

A list of matrices or, for mpm_mean a list of 'CompadreMat' objects, all of the same dimension

na.rm

Logical indicating whether missing values should be excluded (see Details). Defaults to FALSE.

Details

If na.rm == TRUE, missing values are ignored in the calculation of the mean matrix. If na.rm == TRUE and a given element is NA in every matrix within x, the value returned for that element will be 0.

Value

A matrix (mat_mean) or a CompadreMat object (mpm_mean).

Author(s)

Patrick Barks <patrick.barks@gmail.com>

Owen R. Jones <jones@biology.sdu.dk>

See Also

Other data management: cdb_flatten(), cdb_id_stages(), cdb_id_studies(), cdb_id(), cdb_mean_matF(), cdb_rbind(), cdb_unflatten(), cdb_unnest(), mpm_elementwise_apply(), mpm_median(), mpm_sd(), string_representation

Examples

# there are four rows for species 'Haplopappus_radiatus' in Compadre
mpms <- Compadre$mat[Compadre$SpeciesAuthor == "Haplopappus_radiatus"]

#The object mpms is a list, containing compadre objects
class(mpms)
class(mpms[[1]])

mpm_mean(mpms)

# extract list of matA and take mean
mats <- matA(mpms)
mat_mean(mats)

jonesor/Rcompadre documentation built on Jan. 16, 2024, 12:48 a.m.