safe_ifelse: A safe version of ifelse that preserves class

Description Usage Arguments Details Value Examples

Description

A safe version of ifelse that preserves class

Usage

1
safe_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.

Details

A safe version of ifelse that preserves class. Taken from http://stackoverflow.com/questions/6668963/how-to-prevent-ifelse-from-turning-date-objects-into-numeric-objects

Value

Same as ifelse but preserving the class (works with dates).

Examples

1
2
dates <- as.Date(c('2011-01-01', '2011-01-02', '2011-01-03', '2011-01-04', '2011-01-05'))
safe_ifelse(dates == '2011-01-01', dates - 1, dates)

LyzandeR/D2DF documentation built on May 8, 2019, 3:16 p.m.