ifelseAB | R Documentation |
These low-level functions provide faster alternatives to
some uses of ifelse
.
ifelseAB(test, a, b)
ifelseAX(test, a, x)
ifelseXB(test, x, b)
ifelseXY(test, x, y)
ifelseNegPos(test, x)
ifelse0NA(test)
ifelse1NA(test)
test |
A logical vector. |
a |
A single atomic value. |
b |
A single atomic value. |
x |
A vector of values, of the same length as |
y |
A vector of values, of the same length as |
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
.
A vector of the same length as test
containing values of the
same type as a,b,x,y
.
.
ifelse
x <- runif(4e5)
u <- (x < 0.5)
system.time(ifelse(u, 2, x))
system.time(ifelseAX(u, 2, x))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.