[R] ifelse strips POSIXct class from object
Denis Chabot
chabot.denis at gmail.com
Sun Jun 5 15:17:09 CEST 2011
I did not know this function, thanks a lot Gabor.
Denis
Le 2011-06-05 à 08:48, Gabor Grothendieck a écrit :
> On Sun, Jun 5, 2011 at 8:23 AM, Denis Chabot <chabot.denis at gmail.com> wrote:
>> Hi,
>>
>> I was "losing" my dates in a script and upon inspection, found that my recent switch from separate "if" and "else" to "ifelse" was the cause. But why?
>>
>> my.date = as.POSIXct("2011-06-04 08:00:00")
>> default.date = seq(as.POSIXct("2011-01-01 08:00:00"), as.POSIXct("2011-09-01 08:00:00"), length=15)
>> x = 4 * 60 * 60
>> (my.date + x)
>> (min(default.date) + x)
>> (new.date = ifelse(!is.na(my.date), my.date + x, min(default.date) + x) )
>>
>
> Try replace:
>
> new.date <- replace(my.date, is.na(my.date), min(default.date)) + x
>
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
More information about the R-help
mailing list