Sums and Products

DESCRIPTION:
Returns the number that is the sum or product of all of the elements of all of the arguments. Missing values may optionally be removed before the computations.

USAGE:
sum(..., na.rm=F)
prod(..., na.rm=F)

REQUIRED ARGUMENTS:
...:
numeric or complex objects. Missing values (NAs) are allowed, but will cause the value returned to be NA, unless na.rm=TRUE.

OPTIONAL ARGUMENTS:
na.rm=:
logical flag: should missing values be removed before computation? This must be specified in the na.rm= form.

VALUE:
the sum or product of all the elements of all the arguments. If the total length of all the arguments is 0, sum returns 0 and prod returns 1.

DETAILS:
These functions are members of the Summary group of generic functions.

WARNING:
The sum function performs integer arithmetic if all of the numbers are considered integers. If overflow occurs, integer arithmetic "wraps around" rather than producing an error or an NA. For example, sum(as.integer(c(2147483647,34))) returns -2147483615.

SEE ALSO:
cumsum , Arithmetic .

EXAMPLES:
geo.mean <- function(x) prod(x)^(1/length(x))

sum(1:4)