spatstat.utils (version 1.17-0)

ifelseAB: Conditional Selection

Description

These low-level functions provide faster alternatives to some uses of ifelse.

Usage

ifelseAB(test, a, b)
ifelseAX(test, a, x)
ifelseXB(test, x, b)
ifelseXY(test, x, y)
ifelseNegPos(test, x)
ifelse0NA(test)
ifelse1NA(test)

Arguments

test

A logical vector.

a

A single atomic value.

b

A single atomic value.

x

A vector of values, of the same length as test.

y

A vector of values, of the same length as test.

Value

A vector of the same length as test containing values of the same type as a,b,x,y.

Details

These low-level functions provide faster alternatives to some uses of ifelse. They were developed by trial-and-error comparison of computation times of different expressions.

ifelse0NA(test) is equivalent to ifelse(test, 0, NA).

ifelse1NA(test) is equivalent to ifelse(test, 1, NA).

ifelseAB(test, a, b) is equivalent to ifelse(test, a, b) where a and b must be single values.

ifelseAX(test, a, x) is equivalent to ifelse(test, a, x) where a must be a single value, and x a vector of the same length as test.

ifelseXB(test, x, b) is equivalent to ifelse(test, x, b) where b must be a single value, and x a vector of the same length as test.

ifelseXY(test, x, y) is equivalent to ifelse(test, x, y) where x and y must be vectors of the same length as test.

ifelseNegPos(test, x) is equivalent to ifelse(test, x, -x) where x must be a vector of the same length as test.

See Also

ifelse

Examples

Run this code
# NOT RUN {
   x <- runif(4e5)
   u <- (x < 0.5)
   system.time(ifelse(u, 2, x))
   system.time(ifelseAX(u, 2, x))
# }

Run the code above in your browser using DataLab