Learn R Programming

dataprep (version 0.1.8)

transform_data: 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)

Value

A data frame with transformed variables.

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.

Examples

Run this code
# 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)

Run the code above in your browser using DataLab