Learn R Programming

iNZightTools (version 1.13.0)

transformVar: Transform data of a numeric variable

Description

Transform the values of a numeric variable by applying a mathematical function

Usage

transformVar(
  .data,
  var,
  transformation,
  name = sprintf("%s.%s", transformation, var)
)

Value

the original dataframe containing a new column of the transformed variable with tidyverse code attached

Arguments

.data

a dataframe with the variables to transform

var

a character of the numeric variable in .data to transform

transformation

a name of a valid mathematical function that can be applied to numeric values, eg. "log", "exp", "sqrt". For squaring, use "square"; for inverting, use "reciprocal"

name

the name of the new variable

Author

Owen Jin

See Also

code

Examples

Run this code
transformed <- transformVar(iris, var = "Petal.Length",
    transformation = "log")
cat(code(transformed))
head(transformed)

Run the code above in your browser using DataLab