Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

standardize

Standardize vectors, data frames, and survey designs


Description

This function is a wrapper around gscale() that is configured to do a conventional standardization of continuous variables, mean-centering and dividing by one standard deviation.

Usage

standardize(
  data = NULL,
  vars = NULL,
  binary.inputs = "center",
  binary.factors = TRUE,
  weights = NULL
)

Arguments

data

A data frame or survey design. Only needed if you would like to rescale multiple variables at once. If x = NULL, all columns will be rescaled. Otherwise, x should be a vector of variable names. If x is a numeric vector, this argument is ignored.

vars

If data is a data.frame or similar, you can scale only select columns by providing a vector column names to this argument.

binary.inputs

Options for binary variables. Default is center; 0/1 keeps original scale; -0.5/0.5 rescales 0 as -0.5 and 1 as 0.5; center subtracts the mean; and full subtracts the mean and divides by 2 sd.

binary.factors

Coerce two-level factors to numeric and apply scaling functions to them? Default is TRUE.

weights

A vector of weights equal in length to x. If iterating over a data frame, the weights will need to be equal in length to all the columns to avoid errors. You may need to remove missing values before using the weights.

Details

Some more information can be found in the documentation for gscale()

Value

A transformed version of the data argument.

See Also

Other standardization: center_mod(), center(), gscale(), scale_mod()

Examples

# Standardize just the "qsec" variable in mtcars
standardize(mtcars, vars = "qsec")

jtools

Analysis and Presentation of Social Scientific Data

v2.1.3
MIT + file LICENSE
Authors
Jacob A. Long [aut, cre] (<https://orcid.org/0000-0002-1582-6214>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.