case: 'data.table::fcase()' with vectorized default

View source: R/case.R

caseR Documentation

data.table::fcase() with vectorized default

Description

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.

Usage

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))

mtfairbanks/gdt documentation built on April 12, 2024, 6:51 p.m.