This function returns the sum of an numeric array (e.g. vector or matrix) while keeping its attributes.

sumKeepAttr( x, keepNames = FALSE, na.rm = FALSE )

Arguments

x

an numeric array (e.g. vector or matrix).

keepNames

logical. Should the name(s) of the element(s) ofx be assigned to the returned sum? (only relevant if codex has only one element).

na.rm

logical. Passed to sum. Should missing values be removed?

Value

the sum (see sum).

Author

Arne Henningsen

See also

Examples

a <- 1:10
attr( a, "min" ) <- 1
attr( a, "max" ) <- 10
sum(a)
#> [1] 55
sumKeepAttr(a)
#> [1] 55
#> attr(,"min")
#> [1] 1
#> attr(,"max")
#> [1] 10