standardize_variable: Standardize variables in a data set.

View source: R/standarize_variable.R

standardize_variableR Documentation

Standardize variables in a data set.

Description

standardize_variable() standardizes the selected columns in a data.frame using base::scale(). By default, this function overwrites the column to be scaled. Use the suffix argument to avoid this behavior.

standardize_variable() and standardise_variable() are synonyms.

Usage

standardize_variable(data, cols = dplyr::everything(), suffix = NULL)

standardise_variable(data, cols = dplyr::everything(), suffix = NULL)

Arguments

data

A data frame containing the variables to standardize.

cols

<tidy-select> Columns to standardize. Defaults to dplyr::everything().

suffix

A character suffix to be added to the scaled variables names. When suffix is set toNULL, the standardize_variable() function will overwrite the scaled variables. Defaults to NULL.

Value

A data frame with the standardized columns.

standardize_variable and grouped_df

Note that standardize_variable ignores grouping. Meaning that if you call this function on a grouped data frame (see dplyr::grouped_df), the overall variables' mean and standard deviation will be used for the standardization.

Examples

ho_et_al %>%
  standardize_variable(sdo)

ho_et_al %>%
  standardize_variable(c(sdo, linkedfate), suffix = "scaled")

JSmediation documentation built on Feb. 16, 2023, 7:25 p.m.