centers: Centering and/or Standardizing Numeric Data

Description Usage Arguments Details Value See Also Examples

View source: R/quest_functions.R

Description

centers centers and/or standardized data. It is an alternative to scale.default that returns a data.frame rather than a numeric matrix.

Usage

1
centers(data, vrb.nm, center = TRUE, scale = FALSE, suffix)

Arguments

data

data.frame of data.

vrb.nm

character vector of colnames from data specifying the variables.

center

logical vector with length 1 specifying whether grand-mean centering should be done.

scale

logical vector with length 1 specifying whether grand-SD scaling should be done.

suffix

character vector with a single element specifying the string to append to the end of the colnames of the return object. The default depends on the center and scale arguments: 1)if center = TRUE and scale = FALSE, then suffix = "_c", 2) if center = FALSE and scale = TRUE, then suffix = "_s", 3) if center = TRUE and scale = TRUE, then suffix = "_z", 4) if center = FALSE and scale = FALSE, then suffix = "".

Details

centers first coerces data[vrb.nm] to a matrix in preparation for the call to scale.default. If the coercion results in a non-numeric matrix (e.g., any columns in data[vrb.nm] are character vectors or factors), then an error is returned.

Value

data.frame of centered and/or standardized variables with colnames specified by paste0(vrb.nm, suffix).

See Also

center centers_by center_by scale.default

Examples

1
2
3
4
5
6
7
centers(data = mtcars, vrb.nm = c("disp","hp","drat","wt","qsec"))
centers(data = mtcars, vrb.nm = c("disp","hp","drat","wt","qsec"),
   scale = TRUE)
centers(data = mtcars, vrb.nm = c("disp","hp","drat","wt","qsec"),
   center = FALSE, scale = TRUE)
centers(data = mtcars, vrb.nm = c("disp","hp","drat","wt","qsec"),
   scale = TRUE, suffix = "_std")

quest documentation built on Sept. 10, 2021, 5:07 p.m.

Related to centers in quest...