Learn R Programming

JSmediation (version 0.2.3)

standardize_variable: 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)

Value

A data frame with the standardized columns.

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.

<code>standardize_variable</code> and <code>grouped_df</code>

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

Run this code
ho_et_al %>%
  standardize_variable(sdo)

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

Run the code above in your browser using DataLab