rowMads {MatrixGenerics}R Documentation

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

rowMads(x, rows = NULL, cols = NULL, center = NULL, constant = 1.4826,
  na.rm = FALSE, ...)

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

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

colMads(x, rows = NULL, cols = NULL, center = NULL, constant = 1.4826,
  na.rm = FALSE, ...)

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

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

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, NAs are excluded first, otherwise not.

...

Additional arguments passed to specific methods.

dim.

An integer vector of length two specifying the dimension of x, essential when x is a numeric vector. Note, that this is not a generic argument and not all methods need provide it.

Details

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

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)
  
  rowMads(mat)
  colMads(mat)
  

[Package MatrixGenerics version 1.2.1 Index]