On Dec 30, 2007 10:47 AM, Peter Dalgaard <[EMAIL PROTECTED]> wrote: > Gabor Grothendieck wrote: > > Read the warning in ?ifelse > Yep. > > And, yes, it is annoying that ifelse() strips attributes, including > class, but it is one of those things that have been in the S languages > "forever", and nobody really wants to mess with. The fundamental issue > is that you need the result to be able to hold values from both of the > "yes" and the "no" arguments and there is no guarantee that that is > possible outside of the R base types. > > You'd like to have things like these "work" > > d <- as.Date(c("1994-3-4", "1996-3-1")) > > ifelse(d > "1996-1-1", "1996-1-1", d) > > ifelse(d <= "1996-1-1", d, "1996-1-1") > > in the sense that the result is a Date object, but once you start > thinking about the details of how it _might_ work, you find that things > aren't all that simple. If there was a general mechanism for coercion > between classes, then maybe it could be done, but there isn't any.
But wouldn't it be better/simpler to say that the yes and no arguments should be of the same "type"? (I realise that this would be difficult to enforce in R). In what cases is it actually sensible/useful to have different types in the yes and no arguments? Wrt the dates, I have always wondered if it would be nice to have a date primitive - e.g. in microsoft access sql, #1996-1-1# is a date (vs "1996-1-1" the string). (Although access uses your system dates settings to determine whether #1/4/07# is 4 Jan or 1 Mar, which makes portability a real pain) Hadley -- http://had.co.nz/ ______________________________________________ R-help@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.