R: Calculates the sum for each row (column) in a matrix

rowSums2 {matrixStats} | R Documentation

## Calculates the sum for each row (column) in a matrix

### Description

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

### Usage

    rowSums2(x, rows = NULL, cols = NULL, na.rm = FALSE, dim. = dim(x), ...)

    colSums2(x, rows = NULL, cols = NULL, na.rm = FALSE, dim. = dim(x), ...)

### Arguments

`x` | A `numeric` or a `logical` NxK `matrix`.
`rows, cols` | A `vector` indicating subset of rows (and/or columns) to operate over. If `NULL`, no subsetting is done.
`na.rm` | If `TRUE`, `NA`s are excluded first, otherwise not.
`dim.` | An `integer` `vector` of length two specifying the dimension of `x`, also when not a `matrix`.
`...` | Not used.

### Details

The implementation of `rowSums2()` and `colSums2()` is optimized for both speed and memory.

### Value

Returns a `numeric` `vector` of length N (K).

### Author(s)

Henrik Bengtsson

[Package matrixStats version 0.57.0 Index]