Learn R Programming

miscTools (version 0.6-30)

sumKeepAttr: Sum of an Array While Keeping its Attributes

Description

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

Usage

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

Value

the sum (see sum).

Arguments

x

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

keepNames

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

na.rm

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

Author

Arne Henningsen

See Also

Examples

Run this code
a <- 1:10
attr( a, "min" ) <- 1
attr( a, "max" ) <- 10
sum(a)
sumKeepAttr(a)

Run the code above in your browser using DataLab