[R] chron blues

Kurt Hornik Kurt.Hornik at ci.tuwien.ac.at
Tue Jan 2 18:46:45 CET 2001


>>>>> Peter Dalgaard BSA writes:

> Bernie McConnell <bm8 at st-andrews.ac.uk> writes:
>> GoodDay,
>> 
>> Could someone please tell me why b (below) does not return a vector of 10
>> chron objects?  Hopefuly I am being remarkably naive or have missed
>> something obvious in the chron documentation.  I'm running Win NT 4.0

> I don't think you're particularly naive...
> The root of this seems to be this

> Browse[1]> unclass(e1)+c(1.5,1.5)
> [1] 3658.5 3658.5
> Browse[1]> unclass(e1)+c(1.5)
> [1] 3658.5
> attr(,"format")
> [1] "d/m/y" "h:m:s"
> attr(,"origin")
> month   day  year 
>     1     1  1970 


> This is a generic issue, recycling kills attributes:

>> x<-1
>> attr(x,"foo")<-"bar"
>> x+1
> [1] 2
> attr(,"foo")
> [1] "bar"
>> x+1:2
> [1] 2 3

> I forget whether there's a logic to this, but S-Plus 3.4 is doing the
> same thing. Hence, Ops.dates inside chron probably needs fixing.
> Specifically at the line

>    val <- NextMethod(.Generic)

> (original problem:)

>> > library(chron)
>> > gps.start.date <<- chron("06/01/80",
>> +                         "00:00:00",  
>> +                         format=c("d/m/y","h:m:s"))
> ..
>> <bold>> b <<- gps.start.date + rep(1.5,10)

Thanks for spotting this, Peter.

Bernie, could we convince you to use the date/time features added to R
1.2.0 instead?

R> as.POSIXct("1980-06-01") + rep(1.5,10)
 [1] "1980-06-01 00:00:01" "1980-06-01 00:00:01" "1980-06-01 00:00:01"
 [4] "1980-06-01 00:00:01" "1980-06-01 00:00:01" "1980-06-01 00:00:01"
 [7] "1980-06-01 00:00:01" "1980-06-01 00:00:01" "1980-06-01 00:00:01"
[10] "1980-06-01 00:00:01"

works without any problems ... (although you perhaps want to add 1.5
days rather than seconds)

-k
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list