Piecewise function

Mainly present to allow the use of it in IQRmodels. Assumes that x is defined outside of it.

piecewise(...)

Arguments

...

Value1, condition1, value2, condition2, value3, ..., valueN

Value

Value1 if condition1 is true, valueN-1 if condition N-1 is true, valueN if no condition is true. If several conditions are true the value for the first condition that is true is returned.

Examples

if (FALSE) { # \dontrun{
# Make sure to use gt instead of ">" in IQRmodels!

# fails because x is not defined:
# rm(x)
# piecewise(0, gt(x,0), 1, le(x,0), 1)

# works:
x <- 1
piecewise(0, lt(x, 0), 1, ge(x, 0), 1)
x <- -1
piecewise(0, lt(x, 0), 1, ge(x, 0), 1)
} # }