rowProds: Calculates the product for each row (column) in a matrix

Description Usage Arguments Details Value Missing values Author(s)

Description

Calculates the product for each row (column) in a matrix.

Usage

1
2
3
 rowProds(x, na.rm=FALSE, method=c("expSumLog", "direct"), ...)
 colProds(x, na.rm=FALSE, method=c("expSumLog", "direct"), ...)
 product(x, na.rm=FALSE, ...)

Arguments

x

A numeric NxK matrix.

na.rm

If TRUE, missing values are ignored, otherwise not.

method

A character string specifying how each product is calculated.

...

Not used.

Details

If method="expSumLog", then then product() function is used, which calculates the produce via the logarithmic transform (treating negative values specially). This improves the precision and lowers the risk for numeric overflow. If method="direct", the direct product is calculated via the prod() function.

Value

Returns a numeric vector of length N (K).

Missing values

Note, if method="expSumLog", na.rm=FALSE, and x contains missing values (NA or NaN), then the calculated value is also missing value. Note that it depends on platform whether NaN or NA is returned when an NaN exists, cf. is.nan().

Author(s)

Henrik Bengtsson


matrixStats documentation built on May 2, 2019, 4:52 p.m.