standardize.data.frame: Standardize (scale and reduce) Dataframe.

Description Usage Arguments Value Author(s) Examples

View source: R/standardize.R

Description

Selects numeric variables and standardize (Z-score, "normalize") them.

Usage

1
2
3
## S3 method for class 'data.frame'
standardize(x, subset = NULL, except = NULL,
  normalize = FALSE, ...)

Arguments

x

Dataframe.

subset

Character or list of characters of column names to be standardized.

except

Character or list of characters of column names to be excluded from standardization.

normalize

Will perform a normalization instead of a standardization. This scales all numeric variables in the range 0 - 1.

...

Arguments passed to or from other methods.

Value

Dataframe.

Author(s)

Dominique Makowski

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 
df <- data.frame(
  Participant = as.factor(rep(1:25,each=4)),
  Condition = base::rep_len(c("A", "B", "C", "D"), 100),
  V1 = rnorm(100, 30, .2),
  V2 = runif(100, 3, 5),
  V3 = rnorm(100, 100, 10)
  )

dfZ <- standardize(df)
dfZ <- standardize(df, except="V3")
dfZ <- standardize(df, except=c("V1", "V2"))
dfZ <- standardize(df, subset="V3")
dfZ <- standardize(df, subset=c("V1", "V2"))
dfZ <- standardize(df, normalize=TRUE)

# Respects grouping
dfZ <- df %>%
  dplyr::group_by(Participant) %>%
  standardize(df)

## End(Not run)

neuropsychology/psycho.R documentation built on Sept. 22, 2018, 6:39 p.m.