standardize: Standardize a vector

standardizeR Documentation

Standardize a vector

Description

Standardize a vector. Can use weights and robust measures of central tendency and dispersion. Returns a clean vector as opposed to base-r's scale.

Usage

standardize(x, w = NULL, robust = F, sample = T, focal_group = NULL)

Arguments

x

(num vector) A vector of values.

w

(num vector) A vector of weights.

robust

(log vector) Whether to use robust measures (default false). See mad and median.

sample

(log scalar) Whether this is a sample as opposed to a population (default true).

focal_group

(lgl vector) A subset of the data to standardize the values to. This is useful when you want one subgroup to be the focal group, using their mean/sd as 0/1.

Examples

set.seed(1)
X = rnorm(100, mean = 10, sd = 5)
set.seed(1)
W = runif(100)
standardize(X, W)
standardize(X, robust = T) #almost the same for these data

Deleetdk/kirkegaard documentation built on April 22, 2024, 5:22 p.m.