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.19.0 |
Built: | 2024-11-19 04:25:46 UTC |
Source: | https://github.com/bioc/sparseMatrixStats |
Check if all elements in a row (column) of a matrix-like object are equal to a value.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
value |
The value to search for. |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowAlls
/
matrixStats::colAlls
.
Returns a logical
vector
of length N (K).
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()
.
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)
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.
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowAnyNAs
/
matrixStats::colAnyNAs
.
Returns a logical
vector
of length N (K).
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()
.
mat <- matrix(0, nrow=10, ncol=5) mat[sample(seq_len(5 *10), 5)] <- NA sp_mat <- as(mat, "dgCMatrix") colAnyNAs(sp_mat)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
value |
The value to search for. |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowAnys
/
matrixStats::colAnys
.
Returns a logical
vector
of length N (K).
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()
.
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)
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)
## 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 )
## 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 )
X |
An |
W |
An optional numeric |
S |
An integer |
FUN |
A row-by-row (column-by-column) summary statistic function. It is
applied to to each column (row) subset of |
... |
Additional arguments passed to |
na.rm |
(logical) Argument passed to |
tFUN |
If |
rows , cols
|
A |
**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.
Returns a numeric JxN
(MxJ
) matrix.
matrixStats::rowAvgsPerColSet()
and matrixStats::colAvgsPerRowSet()
which are used when the input is a matrix
or numeric
vector.
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)
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.
## S4 method for signature 'xgCMatrix' colCollapse(x, idxs, cols = NULL, useNames = TRUE) ## S4 method for signature 'xgCMatrix' rowCollapse(x, idxs, rows = NULL, useNames = TRUE)
## S4 method for signature 'xgCMatrix' colCollapse(x, idxs, cols = NULL, useNames = TRUE) ## S4 method for signature 'xgCMatrix' rowCollapse(x, idxs, rows = NULL, useNames = TRUE)
x |
An NxK matrix-like object. |
idxs |
An index |
useNames |
If |
rows , cols
|
A |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowCollapse
/
matrixStats::colCollapse
.
Returns a numeric
vector
of length N (K).
matrixStats::rowCollapse()
and matrixStats::colCollapse()
which are used when the input is a matrix
or numeric
vector.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
value |
The value to search for. |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowCounts
/
matrixStats::colCounts
.
Returns a integer
vector
of length N (K).
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()
.
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)
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.
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowCummaxs
/
matrixStats::colCummaxs
.
Returns a numeric
matrix
with the same
dimensions as x
.
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()
.
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)
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.
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowCummins
/
matrixStats::colCummins
.
Returns a numeric
matrix
with the same
dimensions as x
.
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()
.
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)
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.
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowCumprods
/
matrixStats::colCumprods
.
Returns a numeric
matrix
with the same
dimensions as x
.
matrixStats::rowCumprods()
and
matrixStats::colCumprods()
which
are used when the input is a matrix
or numeric
vector.
base::cumprod()
.
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)
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.
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowCumsums
/
matrixStats::colCumsums
.
Returns a numeric
matrix
with the same
dimensions as x
.
matrixStats::rowCumsums()
and
matrixStats::colCumsums()
which are
used when the input is a matrix
or numeric
vector.
base::cumsum()
.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
lag |
An integer specifying the lag. |
differences |
An integer specifying the order of difference. |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowDiffs
/
matrixStats::colDiffs
.
Returns a numeric
matrix
with one column
(row) less than x: or
.
matrixStats::rowDiffs()
and
matrixStats::colDiffs()
which are used
when the input is a matrix
or numeric
vector.
base::diff()
.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
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 |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowIQRDiffs
/
matrixStats::colIQRDiffs
.
Returns a numeric
vector
of length N (K).
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.
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)
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.
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowIQRs
/
matrixStats::colIQRs
.
Returns a numeric
vector
of length N (K).
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()
.
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)
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.
## 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)
## 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)
lx |
An NxK matrix-like object. Typically |
rows , cols
|
A |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowLogSumExps
/
matrixStats::colLogSumExps
.
Returns a numeric
vector
of length N (K).
matrixStats::rowLogSumExps()
and
matrixStats::colLogSumExps()
which are used when the input is a matrix
or numeric
vector.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
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 |
... |
Additional arguments passed to specific methods. |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowMadDiffs
/
matrixStats::colMadDiffs
.
Returns a numeric
vector
of length N (K).
matrixStats::rowMadDiffs()
and
matrixStats::colMadDiffs()
which
are used when the input is a matrix
or numeric
vector.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
center |
(optional) the center, defaults to the row means |
constant |
A scale factor. See |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowMads
/
matrixStats::colMads
.
Returns a numeric
vector
of length N (K).
matrixStats::rowMads()
and
matrixStats::colMads()
which are used
when the input is a matrix
or numeric
vector.
For non-robust standard deviation estimates, see
rowSds()
.
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)
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.
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowMaxs
/
matrixStats::colMaxs
.
Returns a numeric
vector
of length N (K).
matrixStats::rowMaxs()
and
matrixStats::colMaxs()
which are used
when the input is a matrix
or numeric
vector.
For min estimates, see rowMins()
.
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)
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.
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowMeans2
/
matrixStats::colMeans2
.
Returns a numeric
vector
of length N (K).
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()
.
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)
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.
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowMedians
/
matrixStats::colMedians
.
Returns a numeric
vector
of length N (K).
matrixStats::rowMedians()
and
matrixStats::colMedians()
which are
used when the input is a matrix
or numeric
vector.
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)
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.
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowMins
/
matrixStats::colMins
.
Returns a numeric
vector
of length N (K).
matrixStats::rowMins()
and
matrixStats::colMins()
which are used
when the input is a matrix
or numeric
vector.
For max estimates, see rowMaxs()
.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
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 |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowOrderStats
/
matrixStats::colOrderStats
.
Returns a numeric
vector
of length N (K).
matrixStats::rowOrderStats()
and
matrixStats::colOrderStats()
which are used when the input is a matrix
or numeric
vector.
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)
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
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
useNames |
If |
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()'.
Returns a numeric
vector
of length N (K).
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()
.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
probs |
A numeric vector of J probabilities in [0, 1]. |
na.rm |
If |
type |
An integer specifying the type of estimator. See
|
useNames |
If |
drop |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowQuantiles
/
matrixStats::colQuantiles
.
a numeric
NxJ
(KxJ
)
matrix
, where N (K) is the number of rows (columns) for
which the J values are calculated.
matrixStats::rowQuantiles()
and
matrixStats::colQuantiles()
which
are used when the input is a matrix
or numeric
vector.
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)
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.
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowRanges
/
matrixStats::colRanges
.
a numeric
Nx2
(Kx2
)
matrix
, where N (K) is the number of rows (columns) for
which the ranges are calculated.
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
.
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()
.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
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 |
There are three different methods available for handling ties:
for values with identical values the maximum rank is returned
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'.
for values with identical values the minimum rank is returned.
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.
matrixStats::rowRanks()
and
matrixStats::colRanks()
which are used
when the input is a matrix
or numeric
vector.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
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 |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowSdDiffs
/
matrixStats::colSdDiffs
.
Returns a numeric
vector
of length N (K).
matrixStats::rowSdDiffs()
and
matrixStats::colSdDiffs()
which are
used when the input is a matrix
or numeric
vector.
for the direct standard deviation see rowSds()
.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
center |
(optional) the center, defaults to the row means |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowSds
/
matrixStats::colSds
.
Returns a numeric
vector
of length N (K).
matrixStats::rowSds()
and
matrixStats::colSds()
which are used when
the input is a matrix
or numeric
vector.
For variance estimates, see rowVars()
.
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)
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.
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowSums2
/
matrixStats::colSums2
.
Returns a numeric
vector
of length N (K).
matrixStats::rowSums2()
and
matrixStats::colSums2()
which are used
when the input is a matrix
or numeric
vector.
base::sum()
.
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)
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).
## 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)
## 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)
x |
An NxK matrix-like object. |
rows , cols
|
A |
values |
the values to search for. |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowTabulates
/
matrixStats::colTabulates
.
a numeric
NxJ
(KxJ
)
matrix
, where N (K) is the number of rows (columns) for
which the J values are calculated.
matrixStats::rowTabulates()
and
matrixStats::colTabulates()
which
are used when the input is a matrix
or numeric
vector.
base::table()
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
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 |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowVarDiffs
/
matrixStats::colVarDiffs
.
Returns a numeric
vector
of length N (K).
matrixStats::rowVarDiffs()
and
matrixStats::colVarDiffs()
which
are used when the input is a matrix
or numeric
vector.
for the direct variance see rowVars()
.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
rows , cols
|
A |
na.rm |
If |
center |
(optional) the center, defaults to the row means. |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowVars
/
matrixStats::colVars
.
Returns a numeric
vector
of length N (K).
matrixStats::rowVars()
and
matrixStats::colVars()
which are used
when the input is a matrix
or numeric
vector.
For standard deviation estimates, see rowSds()
.
stats::var()
.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
w |
A |
rows , cols
|
A |
na.rm |
If |
constant |
A scale factor. See |
center |
Not supported at the moment. |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowWeightedMads
/
matrixStats::colWeightedMads
.
Returns a numeric
vector
of length N (K).
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.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
w |
A |
rows , cols
|
A |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowWeightedMeans
/
matrixStats::colWeightedMeans
.
Returns a numeric
vector
of length N (K).
matrixStats::rowWeightedMeans()
and
matrixStats::colWeightedMeans()
which are used when the input is a matrix
or numeric
vector.
See also rowMeans2 for the corresponding unweighted function.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
w |
A |
rows , cols
|
A |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowWeightedMedians
/
matrixStats::colWeightedMedians
.
Returns a numeric
vector
of length N (K).
matrixStats::rowWeightedMedians()
and
matrixStats::colWeightedMedians()
which are used when the input is a matrix
or numeric
vector.
See also rowMedians for the corresponding unweighted function.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
w |
A |
rows , cols
|
A |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowWeightedSds
/
matrixStats::colWeightedSds
.
Returns a numeric
vector
of length N (K).
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.
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)
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.
## 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 )
## 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 )
x |
An NxK matrix-like object. |
w |
A |
rows , cols
|
A |
na.rm |
If |
useNames |
If |
The S4 methods for x
of type matrix
,
array
, table
, or numeric
call
matrixStats::rowWeightedVars
/
matrixStats::colWeightedVars
.
Returns a numeric
vector
of length N (K).
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.
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)
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)