I recently met R code that compared a POSIXlt date object with a date string.
as.POSIXlt.date("2007-02-02") >= "2007-02-01"
[1] FALSE
The result, surprisingly, was FALSE for me. I expected the POSIXlt object to be forced into a character vector, and therefore the inequality should check for TRUE. Then I tried explicit coercion and coercion on the other hand to another type gave true.
as.character(as.POSIXlt.date("2007-02-02")) >= "2007-02-01"
[1] TRUE
and
as.POSIXlt.date("2007-02-02") >= as.POSIXlt.date("2007-02-01")
[1] TRUE
I think that forcing the LHS date object to a character vector is semantically incorrect, because the comparison would then be lexicographical, which is not what it is intended (although in this case it matters TRUE). I'm right?
, . ( FALSE)? R , ?
:
R version 3.1.0 (2014-04-10) -- "Spring Dance"
Platform: x86_64-redhat-linux-gnu (64-bit)
R. .
,