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

mat_mean(x, na.rm = FALSE)

mpm_mean(x, na.rm = FALSE)

Arguments

x

List of matrices (mat_mean) or list of CompadreMat objects (mpm_mean), all of same dimension

na.rm

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

Value

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

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.

Examples

# there are four rows for species 'Haplopappus_radiatus' in Compadre mpms <- Compadre$mat[Compadre$SpeciesAuthor == "Haplopappus_radiatus"] mpm_mean(mpms)
#> A compadre matrix object with 4 stages. #> #> MatrixClassOrganized MatrixClassAuthor #> 1 active Seedling #> 2 active Small reproductive #> 3 active Large reproductive #> 4 active Reproductive #> #> matA: #> 1 2 3 4 #> 1 0.00000 0.0000 0.00000 1.96575 #> 2 0.19725 0.4090 0.17650 0.15400 #> 3 0.03250 0.1605 0.38175 0.37500 #> 4 0.00000 0.1175 0.26100 0.37150 #> #> matU: #> 1 2 3 4 #> 1 0.00000 0.0000 0.00000 0.0000 #> 2 0.19725 0.4090 0.17650 0.1540 #> 3 0.03250 0.1605 0.38175 0.3750 #> 4 0.00000 0.1175 0.26100 0.3715 #> #> matF: #> 1 2 3 4 #> 1 0 0 0 1.96575 #> 2 0 0 0 0.00000 #> 3 0 0 0 0.00000 #> 4 0 0 0 0.00000 #> #> matC: #> 1 2 3 4 #> 1 0 0 0 0 #> 2 0 0 0 0 #> 3 0 0 0 0 #> 4 0 0 0 0 #>
# extract list of matA and take mean mats <- matA(mpms) mat_mean(mats)
#> A1 A2 A3 A4 #> [1,] 0.00000 0.0000 0.00000 1.96575 #> [2,] 0.19725 0.4090 0.17650 0.15400 #> [3,] 0.03250 0.1605 0.38175 0.37500 #> [4,] 0.00000 0.1175 0.26100 0.37150