Package 'sparseMatrixStats'

Title: Summary Statistics for Rows and Columns of Sparse Matrices
Description: High performance functions for row and column operations on sparse matrices. For example: col / rowMeans2, col / rowMedians, col / rowVars etc. Currently, the optimizations are limited to data in the column sparse format. This package is inspired by the matrixStats package by Henrik Bengtsson.
Authors: Constantin Ahlmann-Eltze [aut, cre]
Maintainer: Constantin Ahlmann-Eltze <[email protected]>
License: MIT + file LICENSE
Version: 1.17.2
Built: 2024-07-13 02:46:34 UTC
Source: https://github.com/bioc/sparseMatrixStats

Help Index


Check if all elements in a row (column) of a matrix-like object are equal to a value

Description

Check if all elements in a row (column) of a matrix-like object are equal to a value.

Usage

## S4 method for signature 'xgCMatrix'
colAlls(
  x,
  rows = NULL,
  cols = NULL,
  value = TRUE,
  na.rm = FALSE,
  useNames = TRUE
)

## S4 method for signature 'xgCMatrix'
rowAlls(
  x,
  rows = NULL,
  cols = NULL,
  value = TRUE,
  na.rm = FALSE,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

value

The value to search for.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowAlls / matrixStats::colAlls.

Value

Returns a logical vector of length N (K).

See Also

  • matrixStats::rowAlls() and matrixStats::colAlls() which are used when the input is a matrix or numeric vector.

  • For checks if any element is equal to a value, see rowAnys().

  • base::all().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowAlls(mat)
colAlls(mat)

Check if any elements in a row (column) of a matrix-like object is missing

Description

Check if any elements in a row (column) of a matrix-like object is missing.

Usage

## S4 method for signature 'xgCMatrix'
colAnyNAs(x, rows = NULL, cols = NULL, useNames = TRUE)

## S4 method for signature 'xgCMatrix'
rowAnyNAs(x, rows = NULL, cols = NULL, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowAnyNAs / matrixStats::colAnyNAs.

Value

Returns a logical vector of length N (K).

See Also

  • matrixStats::rowAnyNAs() and matrixStats::colAnyNAs() which are used when the input is a matrix or numeric vector.

  • For checks if any element is equal to a value, see rowAnys().

  • base::is.na() and base::any().

Examples

mat <- matrix(0, nrow=10, ncol=5)
  mat[sample(seq_len(5 *10), 5)] <- NA
  sp_mat <- as(mat, "dgCMatrix")
  colAnyNAs(sp_mat)

Check if any elements in a row (column) of a matrix-like object is equal to a value

Description

Check if any elements in a row (column) of a matrix-like object is equal to a value.

Usage

## S4 method for signature 'xgCMatrix'
colAnys(
  x,
  rows = NULL,
  cols = NULL,
  value = TRUE,
  na.rm = FALSE,
  useNames = TRUE
)

## S4 method for signature 'xgCMatrix'
rowAnys(
  x,
  rows = NULL,
  cols = NULL,
  value = TRUE,
  na.rm = FALSE,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

value

The value to search for.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowAnys / matrixStats::colAnys.

Value

Returns a logical vector of length N (K).

See Also

  • matrixStats::rowAnys() and matrixStats::colAnys() which are used when the input is a matrix or numeric vector.

  • For checks if all elements are equal to a value, see rowAlls().

  • base::any().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowAnys(mat)
colAnys(mat)

Calculates for each row (column) a summary statistic for equally sized subsets of columns (rows)

Description

Calculates for each row (column) a summary statistic for equally sized subsets of columns (rows)

Usage

## S4 method for signature 'xgCMatrix'
colAvgsPerRowSet(
  X,
  W = NULL,
  cols = NULL,
  S,
  FUN = colMeans2,
  ...,
  na.rm = NA,
  tFUN = FALSE
)

## S4 method for signature 'xgCMatrix'
rowAvgsPerColSet(
  X,
  W = NULL,
  rows = NULL,
  S,
  FUN = rowMeans2,
  ...,
  na.rm = NA,
  tFUN = FALSE
)

Arguments

X

An NxM matrix-like object.

W

An optional numeric NxM matrix of weights.

S

An integer KxJ matrix that specifying the J subsets. Each column hold K column (row) indices for the corresponding subset. The range of values is [1, M] ([1,N]).

FUN

A row-by-row (column-by-column) summary statistic function. It is applied to to each column (row) subset of X that is specified by S.

...

Additional arguments passed to FUN.

na.rm

(logical) Argument passed to FUN() as na.rm = na.rm. If NA (default), then na.rm = TRUE is used if X or S holds missing values, otherwise na.rm = FALSE.

tFUN

If TRUE, X is transposed before it is passed to FUN.

rows, cols

A vector indicating the subset (and/or columns) to operate over. If NULL, no subsetting is done.

Details

**Note**: the handling of missing parameters differs from [matrixStats::colAvgsPerRowSet()]. The 'matrixStats' version always removes ‘NA'’s if there are any in the data. This method however does whatever is passed in the '...' parameter.

Value

Returns a numeric JxN (MxJ) matrix.

See Also

Examples

mat <- matrix(rnorm(20), nrow = 5, ncol = 4)
  mat[2, 1] <- NA
  mat[3, 3] <- Inf
  mat[4, 1] <- 0
  
  print(mat)
  
  S <- matrix(1:ncol(mat), ncol = 2)
  print(S)
  
  rowAvgsPerColSet(mat, S = S, FUN = rowMeans)
  rowAvgsPerColSet(mat, S = S, FUN = rowVars)

Extract one cell from each row (column) of a matrix-like object

Description

Extract one cell from each row (column) of a matrix-like object.

Usage

## S4 method for signature 'xgCMatrix'
colCollapse(x, idxs, cols = NULL, useNames = TRUE)

## S4 method for signature 'xgCMatrix'
rowCollapse(x, idxs, rows = NULL, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

idxs

An index vector with the position to extract. It is recycled to match the number of rows (column)

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowCollapse / matrixStats::colCollapse.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowCollapse() and matrixStats::colCollapse() which are used when the input is a matrix or numeric vector.

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
  mat[2, 1] <- NA
  mat[3, 3] <- Inf
  mat[4, 1] <- 0

  print(mat)

  rowCollapse(mat, idxs = 2)
  rowCollapse(mat, idxs = c(1,1,2,3,2))

  colCollapse (mat, idxs = 4)

Count how often an element in a row (column) of a matrix-like object is equal to a value

Description

Count how often an element in a row (column) of a matrix-like object is equal to a value.

Usage

## S4 method for signature 'xgCMatrix'
colCounts(
  x,
  rows = NULL,
  cols = NULL,
  value = TRUE,
  na.rm = FALSE,
  useNames = TRUE
)

## S4 method for signature 'xgCMatrix'
rowCounts(
  x,
  rows = NULL,
  cols = NULL,
  value = TRUE,
  na.rm = FALSE,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

value

The value to search for.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowCounts / matrixStats::colCounts.

Value

Returns a integer vector of length N (K).

See Also

  • matrixStats::rowCounts() and matrixStats::colCounts() which are used when the input is a matrix or numeric vector.

  • For checks if any element is equal to a value, see rowAnys(). To check if all elements are equal, see rowAlls().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowCounts(mat)
colCounts(mat)
  rowCounts(mat, value = 0)
  colCounts(mat, value = Inf, na.rm = TRUE)

Calculates the cumulative maxima for each row (column) of a matrix-like object

Description

Calculates the cumulative maxima for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colCummaxs(x, rows = NULL, cols = NULL, useNames = TRUE)

## S4 method for signature 'dgCMatrix'
rowCummaxs(x, rows = NULL, cols = NULL, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowCummaxs / matrixStats::colCummaxs.

Value

Returns a numeric matrixwith the same dimensions as x.

See Also

  • matrixStats::rowCummaxs() and matrixStats::colCummaxs() which are used when the input is a matrix or numeric vector.

  • For single maximum estimates, see rowMaxs().

  • base::cummax().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowCummaxs(mat)
colCummaxs(mat)

Calculates the cumulative minima for each row (column) of a matrix-like object

Description

Calculates the cumulative minima for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colCummins(x, rows = NULL, cols = NULL, useNames = TRUE)

## S4 method for signature 'dgCMatrix'
rowCummins(x, rows = NULL, cols = NULL, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowCummins / matrixStats::colCummins.

Value

Returns a numeric matrixwith the same dimensions as x.

See Also

  • matrixStats::rowCummins() and matrixStats::colCummins() which are used when the input is a matrix or numeric vector.

  • For single minimum estimates, see rowMins().

  • base::cummin().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowCummins(mat)
colCummins(mat)

Calculates the cumulative product for each row (column) of a matrix-like object

Description

Calculates the cumulative product for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'xgCMatrix'
colCumprods(x, rows = NULL, cols = NULL, useNames = TRUE)

## S4 method for signature 'xgCMatrix'
rowCumprods(x, rows = NULL, cols = NULL, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowCumprods / matrixStats::colCumprods.

Value

Returns a numeric matrixwith the same dimensions as x.

See Also

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowCumprods(mat)
colCumprods(mat)

Calculates the cumulative sum for each row (column) of a matrix-like object

Description

Calculates the cumulative sum for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'xgCMatrix'
colCumsums(x, rows = NULL, cols = NULL, useNames = TRUE)

## S4 method for signature 'xgCMatrix'
rowCumsums(x, rows = NULL, cols = NULL, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowCumsums / matrixStats::colCumsums.

Value

Returns a numeric matrixwith the same dimensions as x.

See Also

  • matrixStats::rowCumsums() and matrixStats::colCumsums() which are used when the input is a matrix or numeric vector.

  • base::cumsum().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowCumsums(mat)
colCumsums(mat)

Calculates the difference between each element of a row (column) of a matrix-like object

Description

Calculates the difference between each element of a row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colDiffs(
  x,
  rows = NULL,
  cols = NULL,
  lag = 1L,
  differences = 1L,
  useNames = TRUE
)

## S4 method for signature 'dgCMatrix'
rowDiffs(
  x,
  rows = NULL,
  cols = NULL,
  lag = 1L,
  differences = 1L,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

lag

An integer specifying the lag.

differences

An integer specifying the order of difference.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowDiffs / matrixStats::colDiffs.

Value

Returns a numeric matrix with one column (row) less than x: Nx(K1)Nx(K-1) or (N1)xK(N-1)xK.

See Also

  • matrixStats::rowDiffs() and matrixStats::colDiffs() which are used when the input is a matrix or numeric vector.

  • base::diff().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowDiffs(mat)
colDiffs(mat)

Calculates the interquartile range of the difference between each element of a row (column) of a matrix-like object

Description

Calculates the interquartile range of the difference between each element of a row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colIQRDiffs(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  diff = 1L,
  trim = 0,
  useNames = TRUE
)

## S4 method for signature 'dgCMatrix'
rowIQRDiffs(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  diff = 1L,
  trim = 0,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

diff

An integer specifying the order of difference.

trim

A double in [0,1/2] specifying the fraction of observations to be trimmed from each end of (sorted) x before estimation.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowIQRDiffs / matrixStats::colIQRDiffs.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowIQRDiffs() and matrixStats::colIQRDiffs() which are used when the input is a matrix or numeric vector.

  • For the direct interquartile range see also rowIQRs.

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowIQRDiffs(mat)
colIQRDiffs(mat)

Calculates the interquartile range for each row (column) of a matrix-like object

Description

Calculates the interquartile range for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'xgCMatrix'
colIQRs(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

## S4 method for signature 'xgCMatrix'
rowIQRs(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowIQRs / matrixStats::colIQRs.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowIQRs() and matrixStats::colIQRs() which are used when the input is a matrix or numeric vector.

  • For a non-robust analog, see rowSds(). For a more robust version see rowMads()

  • stats::IQR().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowIQRs(mat)
colIQRs(mat)

Accurately calculates the logarithm of the sum of exponentials for each row (column) of a matrix-like object

Description

Accurately calculates the logarithm of the sum of exponentials for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'xgCMatrix'
colLogSumExps(lx, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

## S4 method for signature 'xgCMatrix'
rowLogSumExps(lx, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

Arguments

lx

An NxK matrix-like object. Typically lx are log(x) values.

rows, cols

A vector indicating the subset (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowLogSumExps / matrixStats::colLogSumExps.

Value

Returns a numeric vector of length N (K).

See Also

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowLogSumExps(mat)
colLogSumExps(mat)

Calculates the mean absolute deviation of the difference between each element of a row (column) of a matrix-like object

Description

Calculates the mean absolute deviation of the difference between each element of a row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colMadDiffs(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  diff = 1L,
  trim = 0,
  constant = 1.4826,
  ...,
  useNames = TRUE
)

## S4 method for signature 'dgCMatrix'
rowMadDiffs(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  diff = 1L,
  trim = 0,
  constant = 1.4826,
  ...,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

diff

An integer specifying the order of difference.

trim

A double in [0,1/2] specifying the fraction of observations to be trimmed from each end of (sorted) x before estimation.

constant

A scale factor. See mad for details.

...

Additional arguments passed to specific methods.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowMadDiffs / matrixStats::colMadDiffs.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowMadDiffs() and matrixStats::colMadDiffs() which are used when the input is a matrix or numeric vector.

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowMadDiffs(mat)
colMadDiffs(mat)

Calculates the median absolute deviation for each row (column) of a matrix-like object

Description

Calculates the median absolute deviation for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colMads(
  x,
  rows = NULL,
  cols = NULL,
  center = NULL,
  constant = 1.4826,
  na.rm = FALSE,
  useNames = TRUE
)

## S4 method for signature 'dgCMatrix'
rowMads(
  x,
  rows = NULL,
  cols = NULL,
  center = NULL,
  constant = 1.4826,
  na.rm = FALSE,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

center

(optional) the center, defaults to the row means

constant

A scale factor. See stats::mad() for details.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowMads / matrixStats::colMads.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowMads() and matrixStats::colMads() which are used when the input is a matrix or numeric vector.

  • For mean estimates, see rowMeans2() and rowMeans().

  • For non-robust standard deviation estimates, see rowSds().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowMads(mat)
colMads(mat)

Calculates the maximum for each row (column) of a matrix-like object

Description

Calculates the maximum for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colMaxs(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

## S4 method for signature 'dgCMatrix'
rowMaxs(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowMaxs / matrixStats::colMaxs.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowMaxs() and matrixStats::colMaxs() which are used when the input is a matrix or numeric vector.

  • For min estimates, see rowMins().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowMaxs(mat)
colMaxs(mat)

Calculates the mean for each row (column) of a matrix-like object

Description

Calculates the mean for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'xgCMatrix'
colMeans2(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

## S4 method for signature 'xgCMatrix'
rowMeans2(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowMeans2 / matrixStats::colMeans2.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowMeans2() and matrixStats::colMeans2() which are used when the input is a matrix or numeric vector.

  • See also rowMeans() for the corresponding function in base R.

  • For variance estimates, see rowVars().

  • See also the base R version base::rowMeans().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowMeans2(mat)
colMeans2(mat)

Calculates the median for each row (column) of a matrix-like object

Description

Calculates the median for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colMedians(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

## S4 method for signature 'dgCMatrix'
rowMedians(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowMedians / matrixStats::colMedians.

Value

Returns a numeric vector of length N (K).

See Also

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowMedians(mat)
colMedians(mat)

Calculates the minimum for each row (column) of a matrix-like object

Description

Calculates the minimum for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colMins(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

## S4 method for signature 'dgCMatrix'
rowMins(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowMins / matrixStats::colMins.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowMins() and matrixStats::colMins() which are used when the input is a matrix or numeric vector.

  • For max estimates, see rowMaxs().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowMins(mat)
colMins(mat)

Calculates an order statistic for each row (column) of a matrix-like object

Description

Calculates an order statistic for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colOrderStats(
  x,
  rows = NULL,
  cols = NULL,
  which = 1,
  na.rm = FALSE,
  useNames = TRUE
)

## S4 method for signature 'dgCMatrix'
rowOrderStats(
  x,
  rows = NULL,
  cols = NULL,
  which = 1,
  na.rm = FALSE,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

which

An integer index in [1,K] ([1,N]) indicating which order statistic to be returned

na.rm

If TRUE, NAs are excluded first, otherwise not.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowOrderStats / matrixStats::colOrderStats.

Value

Returns a numeric vector of length N (K).

See Also

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
    mat[2, 1] <- 2
    mat[3, 3] <- Inf
    mat[4, 1] <- 0

    print(mat)

    rowOrderStats(mat, which = 1)
    colOrderStats(mat, which = 3)

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

Description

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

Usage

## S4 method for signature 'xgCMatrix'
colProds(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

## S4 method for signature 'xgCMatrix'
rowProds(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

Attention: This method ignores the order of the values, because it assumes that the product is commutative. Unfortunately, for 'double' this is not true. For example 'NaN * NA = NaN', but 'NA * NaN = NA'. This is relevant for this function if there are '+-Inf', because 'Inf * 0 = NaN'. This function returns 'NA' whenever there is 'NA' in the input. This is different from 'matrixStats::colProds()'.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowProds() and matrixStats::colProds() which are used when the input is a matrix or numeric vector.

  • For sums across rows (columns), see rowSums2() (colSums2())

  • base::prod().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowProds(mat)
colProds(mat)

Calculates quantiles for each row (column) of a matrix-like object

Description

Calculates quantiles for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'xgCMatrix'
colQuantiles(
  x,
  rows = NULL,
  cols = NULL,
  probs = seq(from = 0, to = 1, by = 0.25),
  na.rm = FALSE,
  type = 7L,
  useNames = TRUE,
  drop = TRUE
)

## S4 method for signature 'xgCMatrix'
rowQuantiles(
  x,
  rows = NULL,
  cols = NULL,
  probs = seq(from = 0, to = 1, by = 0.25),
  na.rm = FALSE,
  type = 7L,
  useNames = TRUE,
  drop = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

probs

A numeric vector of J probabilities in [0, 1].

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

type

An integer specifying the type of estimator. See stats::quantile(). for more details.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

drop

If TRUE a vector is returned if J == 1.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowQuantiles / matrixStats::colQuantiles.

Value

a numeric NxJ (KxJ) matrix, where N (K) is the number of rows (columns) for which the J values are calculated.

See Also

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowQuantiles(mat)
colQuantiles(mat)

Calculates the minimum and maximum for each row (column) of a matrix-like object

Description

Calculates the minimum and maximum for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colRanges(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

## S4 method for signature 'dgCMatrix'
rowRanges(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowRanges / matrixStats::colRanges.

Value

a numeric Nx2 (Kx2) matrix, where N (K) is the number of rows (columns) for which the ranges are calculated.

Note

Unfortunately for the argument list of the rowRanges() generic function we cannot follow the scheme used for the other row/column matrix summarization generic functions. This is because we need to be compatible with the historic rowRanges() getter for RangedSummarizedExperiment objects. See ?SummarizedExperiment::rowRanges.

See Also

  • matrixStats::rowRanges() and matrixStats::colRanges() which are used when the input is a matrix or numeric vector.

  • For max estimates, see rowMaxs().

  • For min estimates, see rowMins().

  • base::range().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowRanges(mat)
colRanges(mat)

Calculates the rank of the elements for each row (column) of a matrix-like object

Description

Calculates the rank of the elements for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colRanks(
  x,
  rows = NULL,
  cols = NULL,
  ties.method = c("max", "average", "min"),
  preserveShape = FALSE,
  na.handling = c("keep", "last"),
  ...,
  useNames = TRUE
)

## S4 method for signature 'dgCMatrix'
rowRanks(
  x,
  rows = NULL,
  cols = NULL,
  ties.method = c("max", "average", "min"),
  preserveShape = TRUE,
  na.handling = c("keep", "last"),
  ...,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

ties.method

A character string specifying how ties are treated. Note that the default specifies fewer options than the original matrixStats package.

preserveShape

a boolean that specifies if the returned matrix has the same dimensions as the input matrix. By default this is true for 'rowRanks()', but false for 'colRanks()'.

na.handling

string specifying how 'NA's are handled. They can either be preserved with an 'NA' rank ('keep') or sorted in at the end ('last'). Default is 'keep' derived from the behavior of the equivalent

...

Additional arguments passed to specific methods.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

There are three different methods available for handling ties:

'max'

for values with identical values the maximum rank is returned

'average'

for values with identical values the average of the ranks they cover is returned. Note, that in this case the return value is of type 'numeric'.

'min'

for values with identical values the minimum rank is returned.

Value

a matrix of type integer is returned unless ties.method = "average". Ithas dimensions' NxJ (KxJ) matrix, where N (K) is the number of rows (columns) of the input x.

See Also

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowRanks(mat)
colRanks(mat)

Calculates the standard deviation of the difference between each element of a row (column) of a matrix-like object

Description

Calculates the standard deviation of the difference between each element of a row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colSdDiffs(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  diff = 1L,
  trim = 0,
  useNames = TRUE
)

## S4 method for signature 'dgCMatrix'
rowSdDiffs(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  diff = 1L,
  trim = 0,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

diff

An integer specifying the order of difference.

trim

A double in [0,1/2] specifying the fraction of observations to be trimmed from each end of (sorted) x before estimation.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowSdDiffs / matrixStats::colSdDiffs.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowSdDiffs() and matrixStats::colSdDiffs() which are used when the input is a matrix or numeric vector.

  • for the direct standard deviation see rowSds().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowSdDiffs(mat)
colSdDiffs(mat)

Calculates the standard deviation for each row (column) of a matrix-like object

Description

Calculates the standard deviation for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'xgCMatrix'
colSds(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  center = NULL,
  useNames = TRUE
)

## S4 method for signature 'xgCMatrix'
rowSds(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  center = NULL,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

center

(optional) the center, defaults to the row means

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowSds / matrixStats::colSds.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowSds() and matrixStats::colSds() which are used when the input is a matrix or numeric vector.

  • For mean estimates, see rowMeans2() and rowMeans().

  • For variance estimates, see rowVars().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowSds(mat)
colSds(mat)

Calculates the sum for each row (column) of a matrix-like object

Description

Calculates the sum for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'xgCMatrix'
colSums2(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

## S4 method for signature 'xgCMatrix'
rowSums2(x, rows = NULL, cols = NULL, na.rm = FALSE, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowSums2 / matrixStats::colSums2.

Value

Returns a numeric vector of length N (K).

See Also

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowSums2(mat)
colSums2(mat)

Tabulates the values in a matrix-like object by row (column)

Description

Tabulates the values in a matrix-like object by row (column).

Usage

## S4 method for signature 'xgCMatrix'
colTabulates(x, rows = NULL, cols = NULL, values = NULL, useNames = TRUE)

## S4 method for signature 'xgCMatrix'
rowTabulates(x, rows = NULL, cols = NULL, values = NULL, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

values

the values to search for.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowTabulates / matrixStats::colTabulates.

Value

a numeric NxJ (KxJ) matrix, where N (K) is the number of rows (columns) for which the J values are calculated.

See Also

Examples

mat <- matrix(rpois(15, lambda = 3), nrow = 5, ncol = 3)
  mat[2, 1] <- NA_integer_
  mat[3, 3] <- 0L
  mat[4, 1] <- 0L

  print(mat)

  rowTabulates(mat)
  colTabulates(mat)

  rowTabulates(mat, values = 0)
  colTabulates(mat, values = 0)

Calculates the variance of the difference between each element of a row (column) of a matrix-like object

Description

Calculates the variance of the difference between each element of a row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colVarDiffs(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  diff = 1L,
  trim = 0,
  useNames = TRUE
)

## S4 method for signature 'dgCMatrix'
rowVarDiffs(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  diff = 1L,
  trim = 0,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

diff

An integer specifying the order of difference.

trim

A double in [0,1/2] specifying the fraction of observations to be trimmed from each end of (sorted) x before estimation.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowVarDiffs / matrixStats::colVarDiffs.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowVarDiffs() and matrixStats::colVarDiffs() which are used when the input is a matrix or numeric vector.

  • for the direct variance see rowVars().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowVarDiffs(mat)
colVarDiffs(mat)

Calculates the variance for each row (column) of a matrix-like object

Description

Calculates the variance for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'xgCMatrix'
colVars(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  center = NULL,
  useNames = TRUE
)

## S4 method for signature 'xgCMatrix'
rowVars(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  center = NULL,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

center

(optional) the center, defaults to the row means.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowVars / matrixStats::colVars.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowVars() and matrixStats::colVars() which are used when the input is a matrix or numeric vector.

  • For mean estimates, see rowMeans2() and rowMeans().

  • For standard deviation estimates, see rowSds().

  • stats::var().

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowVars(mat)
colVars(mat)

Calculates the weighted median absolute deviation for each row (column) of a matrix-like object

Description

Calculates the weighted median absolute deviation for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colWeightedMads(
  x,
  w = NULL,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  constant = 1.4826,
  center = NULL,
  useNames = TRUE
)

## S4 method for signature 'dgCMatrix'
rowWeightedMads(
  x,
  w = NULL,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  constant = 1.4826,
  center = NULL,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

w

A numeric vector of length K (N) that specifies by how much each element is weighted.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

constant

A scale factor. See stats::mad() for details.

center

Not supported at the moment.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowWeightedMads / matrixStats::colWeightedMads.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowWeightedMads() and matrixStats::colWeightedMads() which are used when the input is a matrix or numeric vector.

  • See also rowMads for the corresponding unweighted function.

Examples

mat <- matrix(0, nrow=10, ncol=5)
  mat[sample(prod(dim(mat)), 25)] <- rpois(n=25, 5)
  sp_mat <- as(mat, "dgCMatrix")
  weights <- rnorm(10, mean=1, sd=0.1)

  # sparse version
  sparseMatrixStats::colWeightedMads(sp_mat, weights)

  # Attention the result differs from matrixStats
  # because it always uses 'interpolate=FALSE'.
  matrixStats::colWeightedMads(mat, weights)

Calculates the weighted mean for each row (column) of a matrix-like object

Description

Calculates the weighted mean for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'xgCMatrix'
colWeightedMeans(
  x,
  w = NULL,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  useNames = TRUE
)

## S4 method for signature 'xgCMatrix'
rowWeightedMeans(
  x,
  w = NULL,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

w

A numeric vector of length K (N) that specifies by how much each element is weighted.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowWeightedMeans / matrixStats::colWeightedMeans.

Value

Returns a numeric vector of length N (K).

See Also

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)
w <- rnorm(n = 5, mean = 3)
rowWeightedMeans(mat, w = w[1:3])
colWeightedMeans(mat, w = w)

Calculates the weighted median for each row (column) of a matrix-like object

Description

Calculates the weighted median for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colWeightedMedians(
  x,
  w = NULL,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  useNames = TRUE
)

## S4 method for signature 'dgCMatrix'
rowWeightedMedians(
  x,
  w = NULL,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

w

A numeric vector of length K (N) that specifies by how much each element is weighted.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowWeightedMedians / matrixStats::colWeightedMedians.

Value

Returns a numeric vector of length N (K).

See Also

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)
w <- rnorm(n = 5, mean = 3)
rowWeightedMedians(mat, w = w[1:3])
colWeightedMedians(mat, w = w)

Calculates the weighted standard deviation for each row (column) of a matrix-like object

Description

Calculates the weighted standard deviation for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'xgCMatrix'
colWeightedSds(
  x,
  w = NULL,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  useNames = TRUE
)

## S4 method for signature 'xgCMatrix'
rowWeightedSds(
  x,
  w = NULL,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

w

A numeric vector of length K (N) that specifies by how much each element is weighted.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowWeightedSds / matrixStats::colWeightedSds.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowWeightedSds() and matrixStats::colWeightedSds() which are used when the input is a matrix or numeric vector.

  • See also rowSds for the corresponding unweighted function.

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)
w <- rnorm(n = 5, mean = 3)
rowWeightedSds(mat, w = w[1:3])
colWeightedSds(mat, w = w)

Calculates the weighted variance for each row (column) of a matrix-like object

Description

Calculates the weighted variance for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'xgCMatrix'
colWeightedVars(
  x,
  w = NULL,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  useNames = TRUE
)

## S4 method for signature 'xgCMatrix'
rowWeightedVars(
  x,
  w = NULL,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

w

A numeric vector of length K (N) that specifies by how much each element is weighted.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values (NA or NaN) are omitted from the calculations.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowWeightedVars / matrixStats::colWeightedVars.

Value

Returns a numeric vector of length N (K).

See Also

  • matrixStats::rowWeightedVars() and matrixStats::colWeightedVars() which are used when the input is a matrix or numeric vector.

  • See also rowVars for the corresponding unweighted function.

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)
w <- rnorm(n = 5, mean = 3)
rowWeightedVars(mat, w = w[1:3])
colWeightedVars(mat, w = w)

Union of double and logical column-sparse matrices

Description

Union of dgCMatrix and lgCMatrix