Learn R Programming

sjstats (version 0.7.1)

std: Standardize and center variables

Description

std() computes a z-transformation (standardized and centered) on the input. center() centers the input.

Usage

std(data, ..., include.fac = TRUE, append = FALSE)
center(data, ..., include.fac = TRUE, append = FALSE)

Arguments

data
A variable that should be standardized or centered, or a data frame with such variables.
...
Optional, names of the variables with that should be standardized or centered. Required, if either data is a data frame and no vector, and only selected variables from data should be used in the function.
include.fac
Logical, if TRUE, factors will be converted to numeric vectors and also standardized or centered.
append
Logical, if TRUE and data is a data frame, the standardized or centered variables will be appended as new columns to data. Variable (column) names will be the same, however, standardized variables get the suffix "_z", while centered variables get the suffix "_c".

Value

Either a vector with standardized or centered variables, if data was a vector; or a tibble with standardized or centered variables, if data was a data frame. If append = TRUE, standardized and centered variables are added as new columns to data.

Examples

Run this code
library(dplyr)
data(efc)
std(efc$c160age) %>% head()
std(efc, e17age, c160age) %>% head()
std(efc, e17age, c160age, append = TRUE) %>% head()

center(efc$c160age) %>% head()
center(efc, e17age, c160age) %>% head()
center(efc, e17age, c160age, append = TRUE) %>% head()

# NOTE!
std(efc$e17age) # returns a vector
std(efc, e17age) # returns a tibble

Run the code above in your browser using DataLab