Package 'rescale'

Title: Rescales Data Based on Other Data
Description: Rescales columns in a data frame based on the columns in a second data frame. For example a column can be rescaled by subtracting the mean and dividing by the standard deviation. The user can pass the names of functions which calculate the value to subtract and/or the value to divide by. The package was developed for making predictions based on models with rescaled variables. For the predictions to be valid the new data frame must have its predictor variables rescaled based on the original data.
Authors: Joe Thorley [cre, aut] , Ayla Pearson [ctb] , Nadine Hussein [ctb] , Poisson Consulting [fnd, cph]
Maintainer: Joe Thorley <[email protected]>
License: MIT + file LICENSE
Version: 0.0.0.9006
Built: 2024-12-01 07:42:41 UTC
Source: https://github.com/poissonconsulting/rescale

Help Index


Check Valid Rescalers

Description

Check Valid Rescalers

Usage

check_valid_rescalers(x, x_name = substitute(x))

Arguments

x

A character vector to test for valid rescalers.

x_name

A string of the object name.

Value

An informative error if the check failed otherwise the original object.


Get Rescaler Colnames

Description

Get Rescaler Colnames

Usage

get_rescaler_colnames(x)

Arguments

x

A character vector.

Value

A character vector of the rescaler column names.

Examples

get_rescaler_colnames(c("log(mean)*", "sqrt(cc)="))

Rescale Data

Description

Centers and scales columns in a data frame based on the columns in a second data frame. A column is centered by subtracting the mean and scaled by dividing by the standard deviation. Columns in scale are automatically added to center so they are standardised.

Usage

rescale(data, data2 = data, center = character(0), scale = character(0))

Arguments

data

The data frame to center and scale.

data2

A data frame to use for the centering and scaling.

center

A character vector of the columns to center.

scale

A character vector of the columns to scale (after centering).

Value

The data frame with rescaled columns.

See Also

scale, rescale_f and rescale_c

Examples

rescale(datasets::mtcars, scale = "mpg")

Rescale Transformed Data

Description

Rescales transformed columns in a data frame based on the transformed columns in a second data frame. The columns are rescaled by subtracting values and then dividing by values.

Usage

rescale_c(data, data2 = data, colnames = character(0))

Arguments

data

The data frame to rescale.

data2

A data frame to use for the rescaling.

colnames

A character vector of column names to transform and/or rescale.

Details

The column names can include a single function for the transform as well as the following suffices: + (subtract mean), - (subtract min), =(subtract min and add 1), / (divide by sd) and * (subtract mean and divide by sd).

Value

The data frame with transformed and rescaled columns.

See Also

rescale


Rescale Transformed Data

Description

Rescales transformed columns in a data frame based on the transformed columns in a second data frame. The columns are rescaled by subtracting values and then dividing by values.

Usage

rescale_f(
  data,
  data2 = data,
  transform = list(),
  subtract = list(),
  divide_by = list()
)

Arguments

data

The data frame to rescale.

data2

A data frame to use for the rescaling.

transform

A named list where the name(s) indicate the function(s) to use for the transformations and the elements indicate the columns to transform.

subtract

A named list where the name(s) indicate the function(s) to use when determining the value to subtract and the elements indicate the columns.

divide_by

A named list where the name(s) indicate the function(s) to use when determining the value to divide by and the elements indicate the columns.

Value

The data frame with transformed and rescaled columns.

See Also

rescale

Examples

rescale_f(datasets::mtcars,
  transform = list(log = "mpg"),
  subtract = list(mean = c("mpg", "disp"), min = "gear"),
  divide_by = list(sd = c("mpg", "hp"))
)