Dear all,

I have had a "weird" problem in R 3.0.2:

> x
[1] "2006-03-14 12:48:01 CET"  "2006-05-02 11:09:48 CEST"
> str(x)
 POSIXct[1:2], format: "2006-03-14 12:48:01" "2006-05-02 11:09:48"
> x + 6
Error in unclass(e1) + unclass(e2) :
  non-numeric argument to binary operator
> as.POSIXct(x) + 6
Error in unclass(e1) + unclass(e2) :
  non-numeric argument to binary operator

I was puzzled to the max and did not understand what's wrong:

> y <- c(as.POSIXct("2006-03-14 12:48:01 CET"), as.POSIXct("2006-05-02
11:09:48 CEST"))
> y
[1] "2006-03-14 12:48:01 CET"  "2006-05-02 11:09:48 CEST"
> str(y)
 POSIXct[1:2], format: "2006-03-14 12:48:01" "2006-05-02 11:09:48"
> y + 6
[1] "2006-03-14 12:48:07 CET"  "2006-05-02 11:09:54 CEST"

My immediate assumption was, that something was wrong with the internal
representation. After some googling I discovered dput and there it was:

> dput(x)
structure(c("1142336881", "1146560988"), class = c("POSIXct", "POSIXt"))
> dput(y)
structure(c(1142336881, 1146560988), class = c("POSIXct", "POSIXt"))

So on the inside "x" is a character vector, while "y" is a numeric vector.
Ok, seems I need to force conversion to the "sensible" representation:

> xx <- as.POSIXct(as.character(x))
> dput(xx)
structure(c(1142336881, 1146560988), class = c("POSIXct", "POSIXt"), tzone
= "")

Now my questions:

Shouldn't as.POSIXct() force the recommended or canonical internal
representation?
Would you regard this as a bug?
Or is the code, which created x in the first place to blame?

Thanks in advance,

Jens

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to