if_else: Fast if_else

View source: R/if_else.R

if_elseR Documentation

Fast if_else

Description

Fast version of base::ifelse().

Usage

if_else(condition, true, false, missing = NA, ..., ptype = NULL, size = NULL)

Arguments

condition

Conditions to test on

true

Values to return if conditions evaluate to TRUE

false

Values to return if conditions evaluate to FALSE

missing

Value to return if an element of test is NA

...

These dots are for future extensions and must be empty.

ptype

Optional ptype to override output type

size

Optional size to override output size

Examples

x <- 1:5
if_else(x < 3, 1, 0)

# Can also be used inside of mutate()
df <- data.table(x = x)

df %>%
  mutate(new_col = if_else(x < 3, 1, 0))

tidytable documentation built on Sept. 11, 2024, 8:05 p.m.