[R] Date formats

Mikkel Grum mi2kelgrum at yahoo.com
Sun Dec 30 07:45:38 CET 2007

Is the following expected behaviour for a date used in
an ifelse function?

> date <- Sys.Date()
> date
[1] "2007-12-30"
> ifelse(TRUE, date-1, date)
[1] 13876
> ifelse(FALSE, date-1, date)
[1] 13877
> ifelse(TRUE, as.character(date-1), date)
[1] "2007-12-29"
> if (TRUE) {date}
[1] "2007-12-30"

It would seem more natural to me if a date produced
the same format in an if and an ifelse function.
Moreover, as far as I can see the ifelse function
consists of hardly anything but two if functions.

> sessionInfo()
R version 2.6.1 (2007-11-26) 


attached base packages:
[1] stats     graphics  grDevices utils     datasets 
methods   base     

Be a better friend, newshound, and

More information about the R-help mailing list