transform_data: Transform and standardize numeric variables

View source: R/transform_data.R

transform_dataR Documentation

Transform and standardize numeric variables

Description

Applies a transformation (log, sqrt, inverse, Box-Cox, Yeo-Johnson) or standardization (z-score, centering, scaling, min-max, robust scaling) to selected numeric columns. Group-wise transformation is supported.

Usage

transform_data(data, cols = NULL, method = "log", group = NULL,
               lambda = 1.0, verbose = FALSE)

Arguments

data

A data frame or matrix containing numeric variables.

cols

The column indices or names of selected variables. If NULL, all columns are used.

method

Transformation method. One of "log", "log1p", "sqrt", "inverse", "boxcox", "yeojohnson", "zscore", "center", "scale", "minmax", "robust".

group

Optional grouping column for group-wise transformation.

lambda

Parameter for Box-Cox and Yeo-Johnson transformations (default 1.0).

verbose

Logical; if TRUE, prints progress message.

Details

For "boxcox", values must be positive. For "yeojohnson", both positive and negative values are allowed. Standardization methods ignore NA values.

Value

A data frame with transformed variables.

Examples

# Log transformation
transform_data(data[1:100, c(1, 4, 17:19)], cols = 3:5, method = "log")
# Z-score standardization by group
transform_data(data[1:100, c(1, 4, 17:19)], cols = 3:5, method = "zscore", group = 2)

dataprep documentation built on Oct. 1, 2026, 5:07 p.m.