if_else_: if_this_else_that_

if_else_R Documentation

if_this_else_that_

Description

A vectorised if or else function. It checks that the true or false (or the optional missing) arguments have the same type. However it accepts a generic NA. Built upon dplyr's [if_else()] function. The only difference is that the user do not have to specify the type of NA. if_else_ is faster than base [ifelse()] and a tad slower than dplyr's [if_else()]. Attributes are taken from either true or false because one generic NA.

Usage

if_else_(condition, true, false, missing = NULL)

Arguments

condition

logical vector

true

value to replace if condition is true. Must be same length as condition or 1.

false

value to replace if condition is false. Must be same length as condition or 1.

missing

optional. a replacement if condition returns NA. Must be same length as condition or 1.

Details

If the returning vector have attributes (e.g. for factors) it returns the attributes for the first non-generic NA in the order true, false and then missing.

Value

a vector

See Also

vignette("s"), vignette("hablar")

Examples


v <- c(TRUE, FALSE, TRUE, FALSE)
if_else_(v, "true", "false")

v <- c(TRUE, FALSE, NA, FALSE)
if_else_(v, 1, NA, 999)


hablar documentation built on March 31, 2023, 11:54 p.m.