standardize {ensr}R Documentation

Standardize

Description

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

Usage

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

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)

[Package ensr version 0.1.0 Index]