scaler: Scale multiple columns at once

Description Usage Arguments Details Value Examples

View source: R/scaler.R

Description

Center and/or scale multiple columns of a dataframe.

scaler is designed to work with %>% pipelines.

scaler_fit returns fit_object with information used to transform data.

scaler_transform scales data based on the information in the fit_object.

scaler_invert inverts scaling based on the information in the fit_object.

scaler_ and scaler_fit_ are standard evalution versions.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
scaler(data, ..., center = TRUE, scale = TRUE)

scaler_(data, cols = NULL, center = TRUE, scale = TRUE)

scaler_fit(data, ..., center = TRUE, scale = TRUE)

scaler_fit_(data, cols = NULL, center = TRUE, scale = TRUE)

scaler_transform(data, fit_object)

scaler_invert(data, fit_object)

Arguments

data

Dataframe, tbl, vector

..., cols

Variables to include/exclude.

... : You can use same specifications as in dplyr's select.

cols : character vector

If missing, defaults to all non-grouping variables.

center

Logical or logical vector with element for each included column.

scale

Logical or logical vector with element for each included column.

fit_object

Object from scaler_fit used to transform data

Details

Scales each specified column and converts to tibble.

Value

Tibble where selected columns have been scaled.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Attach package
library(LRO.utilities)

# Create dataframe
df <- data.frame('a' = c(1,2,3,4,5,6,7),
                 'b' = c(2,3,4,5,6,7,8))

# Scale and center both columns
scaler(df)

# Scale and center 'b'
scaler(df, b)

# Scale but not center 'a'
scaler(df, a, center = FALSE)

# Scaling multiple columns
scaler(df, a, b)
scaler(df, 1:2)
scaler(df, c(a,b))

# Scaling all but 'a'
scaler(df, -a)

## Fit / Transform / Invert

# Fit scaler
fitted_scaler <- scaler_fit(df, 1:2)

# Transform data
scaled_df <- scaler_transform(df, fitted_scaler)

# Invert scaling
scaler_invert(scaled_df, fitted_scaler)

## Setting scale and center for each column

scaler(df, center = c(TRUE, FALSE),
       scale = c(FALSE, TRUE))

## Standard evalutation versions

scaler_(df, cols = c('b'))
scaler_fit_(df, cols = c('a'))

LudvigOlsen/LRO.utilities documentation built on Nov. 13, 2020, 11:26 a.m.