where: Multiple ifelse clauses

Description Usage Arguments Value Examples

Description

This is a version of ifelse that allows to check against multiple conditions or alternatively a vectorized version of the when function in purrr.

Usage

1
where(.x, ...)

Arguments

.x

Vector of values to match against

...

Either formulas with a condition as LHS (optional) and an action as RHS. Or named arguments that define additional values to match against, i.e. that can be used in the formulas just like .x.

Value

The value resulting from the first valid condition for the given vector element is returned. Formulas without LHS or unnamed values are used as default.

Examples

1
2
3
4
5
where(1:10,
      y = 10:1,
      .x <= 4 ~ y,
      .x <= 6 ~ 11:20,
      ~ -.x)

STAT-UP/statupinternal documentation built on May 9, 2019, 11:43 a.m.