Learn R Programming

tidytable (version 0.5.4)

case.: Case when

Description

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

Note that this function is called differently than dplyr::case_when. See examples.

Usage

case.(..., default = NA)

Arguments

...

Sequence of condition/value designations

default

Default value. Set to NA by default.

Examples

Run this code
# NOT RUN {
library(data.table)

test_df <- tidytable(
  a = 1:10,
  b = 11:20,
  c = c(rep("a", 6), rep("b", 4)),
  d = c(rep("a", 4), rep("b", 6)))

test_df %>%
  mutate.(x = case.(b < 13, 3,
                    a > 4, 2,
                    default = 10))
test_df %>%
  mutate.(x = case.(c == "a", "a",
                    default = d))
# }

Run the code above in your browser using DataLab