Learn R Programming

exams.forge (version 1.0.10)

transformif: Transformation

Description

Transforms x if cond is TRUE by \(\log(a+b*x)\) if p==0 and \((a+b*x)^p)\). Otherwise the transformation can be either applied to each element of x, or to all elements of x.

Usage

transformif(x, cond, a = -abs(min(x)), b = 1, p = 1)

Value

A transformed vector

Arguments

x

vector: values

cond

logical: condition if transformation should be applied

a

numeric: shift (default: -abs(min(x)))

b

numeric: scale (default: 1))

p

numeric: power (default: 1))

Examples

Run this code
x <- rnorm(5)
transformif(x, min(x)<0)  # all transformed elements > 0
transformif(x, x<0)       # only negative elements are transformed

Run the code above in your browser using DataLab