winsorizeMatrix: Winsorizing of an entire matrix

Description Usage Arguments Value Examples

View source: R/winsorizeMatrix.R

Description

Winsorizing of an entire matrix. Here, winsorization consists in replacing extreme values in a matrix by the corresponding upper and lower quantiles.

Usage

1
winsorizeMatrix(mat, low = 1, high = 99, verbose = FALSE)

Arguments

mat

A matrix to winsorize

low

Numeric. A value in [0,100]. All the values below quantile(mat,low/100) are replaced by quantile(mat,low/100)

high

Numeric. A value in [0,100]. All the values above quantile(mat,high/100) are replaced by quantile(mat,high/100)

verbose

Logical. Default to FALSE. If verbose=TRUE, the function will print statistics on the number of values replaced.

Value

A matrix with extreme values replaced by the corresponding quantiles.

Examples

1
2
3
4
5
6
7
8
9
## Create a matrix with random number from N(0,1):
  set.seed(123)
  x <- matrix(rnorm(1e4), ncol=100)
## Replace the top and bottom 1% extreme values by the corresponding quantiles:
  y <- winsorizeMatrix(x, low=1, high=99, verbose = TRUE)
## Add some NA in x:
  x[x>2] <- NA
## winsorizeMatrix still works
  y <- winsorizeMatrix(x, low=1, high=99, verbose = TRUE)

pgpmartin/GeneNeighborhood documentation built on Sept. 2, 2021, 6:37 a.m.