ifelse: Conditional Element Selection

Description Usage Arguments Details Value Examples

View source: R/ifelse.R

Description

Conditional Element Selection

Usage

1
ifelse(test, yes, no, ...)

Arguments

test

an object which can be coerced to logical mode.

yes

return values for true elements of test.

no

return values for false elements of test.

...

further arguments to be passed to cfactor.

Details

A refined version of ifelse that allows for factor appending.

Value

If either yes or no are of class factor, the function returns an object of class factor whereas levels are determined using cfactor internally. Otherwise, the base method is called directly.

Examples

1
2
3
f <- factor(c('c','a','a',NA,'b','a'), levels= c('a','b','c'))
base::ifelse(is.na(f), "g", f) # not nice
refactor::ifelse(is.na(f), "g", f) # probably what you wanted

jonmcalder/refactor documentation built on Nov. 16, 2020, 3:46 a.m.