standardize: Custom Function to Standardize a Variable

Description Usage Arguments Value Examples

View source: R/utility_functions.R

Description

This function centers and scales a variable, and adds attributes that allow the function to convert the standardized variable back into its original scale.

Usage

1
standardize(x, reverse = F)

Arguments

x

a numerical value.

reverse

logical; if true, the function extracts the 'mean' and 'scale' attributes and reverses the standardization.

Value

If reverse is FALSE, returns the standardized values for x, with attributes giving the mean and scale; otherwise, returns the raw, unstandardized values of x.

Examples

1
2
3
4
5
6
x = runif( 30 )
# Standardize the variable
z = my_standardize( x )
# Unstandardize the variable
y = my_standardize( x, reverse = T )
all( x == y )

rettopnivek/utilityf documentation built on March 1, 2021, 7:05 p.m.