[R] Date formats

From: Mikkel Grum <mi2kelgrum_at_yahoo.com>
Date: Sat, 29 Dec 2007 22:45:38 -0800 (PST)

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

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 30 Dec 2007 - 06:50:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 30 Dec 2007 - 10:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.