Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

assignRecode

A variable is transformed in an indicated way


Description

In the variable key framework, the user might request transformations such as the logarithm, exponential, or square root. This is done by including strings in the recodes column, such as "log(x + 1)" or "3 + 1.1 * x + 0.5 * x ^ 2". This function implements the user's request by parsing the character string and applying the indicated re-calculation.

Usage

assignRecode(x, recode = NULL)

Arguments

x

A column to be recoded

recode

A character string using placeholder "x". See examples

Details

In the variable key framework, this is applied to the raw data, after missings are imposed.

Value

A new column

Author(s)

Paul Johnson <pauljohn@ku.edu>

Examples

set.seed(234234)
x <- rpois(100, lambda = 3)
x <- x[order(x)]
str1 <- "log(x + 1)"
xlog <- assignRecode(x, recode = str1)
plot(xlog ~ x, type = "l")
mean(xlog, na.rm = TRUE)
str2 <- "x^2"
xsq <- assignRecode(x, recode = str2)
plot(xsq ~ x, type = "l")
str3 <- "sqrt(x)"
xsrt <- assignRecode(x, recode = str3)

kutils

Project Management Tools

v1.70
GPL-2
Authors
Paul Johnson [aut, cre], Benjamin Kite [aut], Charles Redmon [aut], Jared Harpole [ctb], Kenna Whitley [ctb], Po-Yi Chen [ctb], Shadi Pirhosseinloo [ctb]
Initial release
2020-04-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.