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),
      ..., useNames = NA)

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

### Arguments

`x` | An NxK `matrix` or, if `dim.` is specified, an N * K `vector`.
`rows` | A `vector` indicating subset of rows to operate over. If `NULL`, no subsetting is done.
`cols` | A `vector` indicating subset of columns to operate over. If `NULL`, no subsetting is done.
`na.rm` | If `TRUE`, missing values are excluded.
`dim.` | An `integer` `vector` of length two specifying the dimension of `x`, also when not a `matrix`. Comment: The reason for this argument being named with a period at the end is purely technical (we get a run-time error if we try to name it `dim`).
`...` | Not used.
`useNames` | If `NA`, the default behavior of the function about naming support is remained. If `FALSE`, no naming support is done. Else if `TRUE`, names attributes of result are set.

### 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.61.0 Index]