i: Functions that form a Wrapper around 'ifelse'.

Description Usage Arguments See Also Examples

View source: R/ifelse_wrapper.R

Description

ifelse functions can be nested to do a vectorised if then else evaluation, with multiple if then statements. Although this is functional it often gives messy code. These three functions provide a wrapper, so the code gets cleaner.

Usage

1
2
3
4
5
i(if_stat, then)

e(else_ret)

ie(...)

Arguments

if_stat

Logical condition forming the if statement.

then

Value to be returned, when if_stat is TRUE.

else_ret

Value to be returned, when all if_stats are FALSE.

See Also

https://edwinth.github.io/blog/ifelse-wrapper/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
set.seed(0310)
x <- runif(1000, 1, 20)
y <- runif(1000, 1, 20)
ie(
  i(x < 5 & y < 5,   'A'),
  i(x < 5 & y < 15,  'B'),
  i(x < 5,           'C'),
  i(x < 15 & y < 5,  'D'),
  i(x < 15 & y < 15, 'E'),
  i(y < 5,           'F'),
  i(y < 15,          'G'),
  e('H')
)

EdwinTh/thatssorandom documentation built on Jan. 18, 2020, 2:55 p.m.