pre_process: Perform common preprocessing of numeric data

Description Usage Arguments Details Value Examples

View source: R/pre_process.R

Description

Perform common data transformations

Usage

1
2
3
4
5
6
7
8
9
pre_process(
  data,
  std = TRUE,
  scale_by = 1,
  log_vars = NULL,
  log_base = exp(1),
  zero_start = NULL,
  zero_one = NULL
)

Arguments

data

A data frame or tibble.

std

Standardize numeric/integer variables?

scale_by

A single value to standardize by. See details. Default is 1.

log_vars

Which variables to log. Requires 'vars()'.

log_base

Log base. Default is 'exp(1)'.

zero_start

Which variables to start by zero. Requires 'vars()'.

zero_one

Which variables to rescale from 0 to 1. Requires 'vars()'.

Details

At a minimum, by default, this function will standardize numeric/integer variables in a data set by the value provided to std (1 standard deviation is the default for scale_by). If scale_by is set to zero, the variables will simply be centered and not scaled. This operation will only be performed on variables not provided for the other options.

- It will log variables contained within vars(), with base equal to log_base, which is exp(1) by default (i.e. natural log).

- zero_start will make the minimum value zero, as often done for time index variables in longitudinal data. - zero_one will rescale variables to range from 0 to 1.

This is a bare minimum function, meant to perform common operations quickly/easily. If you're wanting to do more than this, you'll have to do it yourself.

I would have called this function transmute, but it's already taken by dplyr, despite no one ever using it for the purpose of turning into a whirlwind capable of taking out whatever the Galactor may have in store for them.

Value

A data frame that has been processed

Examples

1
2
3
4
5
6
7
library(tidyext)
library(dplyr)

pre_process(mtcars)
pre_process(mtcars, log_vars = vars(mpg, wt))
pre_process(mtcars, zero_start = vars(cyl, gear))
pre_process(mtcars, zero_one = vars(mpg))

m-clark/tidyext documentation built on July 21, 2020, 2:36 a.m.