standardize: Standardize

Description Usage Arguments Examples

View source: R/standardize.R

Description

Center and scale vectors by mean/standard deviation or median/IQR with the option to base the standardization only on unique observations.

Usage

1
2
3
4
5
6
standardize(
  x,
  stats = list(center = "mean", scale = "sd"),
  use_unique = TRUE,
  margin
)

Arguments

x

numeric data to standardize

stats

a list defining the centering and scaling statistics.

use_unique

use only unique values of x when determining the values for the stats.

margin

passed to apply if x is a matrix or array. If you want to use all the data in the array for the calculation of the statistics pass margin = 0.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
x <- 1:100
standardize(x)
standardize(x, stats = list(center = "median", scale = "IQR"))

xmat <- matrix(1:50, nrow = 10)
standardize(xmat, margin = 0)
standardize(xmat, margin = 1)
standardize(xmat, margin = 2)

xarray <- array(1:60, dim = c(5, 2, 6))
standardize(xarray, margin = 0)
standardize(xarray, margin = 1:2)

# Standardize a data.frame
standardize(mtcars)

# a generic list object
alist <- list(x = rep(1:10, 2), y = rnorm(100), z = matrix(1:10, nrow = 2))
standardize(alist, margin = 0)
standardize(alist, margin = 1)

dewittpe/ensr documentation built on March 6, 2020, 5:24 p.m.