standardize_variable {JSmediation} | R 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 |
< |
suffix |
A character suffix to be added to the scaled variables names.
When suffix is set to |
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")