Skip to content
Prev 304072 / 398503 Next

POSIXct-coerced NA's not considered NA by is.na()

Thanks for your reply, Jim.
On 8/24/2012 12:14 PM, jim holtman wrote:
Yes, that's something I may have confounded. Still, the warning I'm
getting is "In as.POSIXlt.POSIXct(x, tz) : NAs introduced by coercion".
 I'm not sure how c()'s coercion works - the warning seems to indicate
that c() is finding as.POSIXct.  That's strange though, since I would
expect to get an error in that case, not just a warning:
Error in as.POSIXlt.character(x, tz, ...) :
  character string is not in a standard unambiguous format
I was expecting that the NA resulting from the coercion would result in
a TRUE value when being operated on by is.na().  Instead, I got:
[1] FALSE
I'm a bit confused about how you get that from dput.  Here's what I see:
structure(c("1345831833", "1345831834", NA, "b"), class = c("POSIXct",
"POSIXt"))

Regardless, I do get the same strange is.na() behavior from the following:
[1] NA
Warning message:
In as.POSIXlt.POSIXct(x, tz) : NAs introduced by coercion
[1] FALSE

As nasty as it may be, shouldn't something showing up as "NA" result in
TRUE when being tested by is.na()?

Just to put some context around this, I was investigating this issue as
I was thinking about converting dataframe columns to dates, and
detecting errors in that conversion.

thanks,
Allie