This function allows you to use multiple if/else statements in one call.

It is called like data.table::fcase(), but allows the user to use a vector as the default argument.

case.(..., default = NA, ptype = NULL, size = NULL)

Arguments

...

Sequence of condition/value designations

default

Default value. Set to NA by default.

ptype

Optional ptype to specify the output type.

size

Optional size to specify the output size.

Examples

df <- tidytable(x = 1:10)

df %>%
  mutate(case_x = case(x < 5, 1,
                       x < 7, 2,
                       default = 3))
#> # A tidytable: 10 × 2
#>        x case_x
#>    <int>  <dbl>
#>  1     1      1
#>  2     2      1
#>  3     3      1
#>  4     4      1
#>  5     5      2
#>  6     6      2
#>  7     7      3
#>  8     8      3
#>  9     9      3
#> 10    10      3