Re: [R] date/time arithmetic

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 01 Dec 2005 - 06:59:49 EST

I don't know what is wrong but you could use the numeric class instead of the difftime class as a workaround:

x <- Sys.time()
y <- x + 3600
diffyx <- as.numeric(y) - as.numeric(x)
identical(y - diffyx, x) # TRUE

On 11/23/05, Parlamis Franklin <fparlamis@mac.com> wrote:
> On the help page "DateTimeClasses {base}" it says:
>
> "One can add or subtract a number of seconds or a difftime object
> from a date-time object, but not add two date-time objects."
>
> However,
>
> > x<-Sys.time(); y<-Sys.time()+3600
> > diff<-y-x
> > x; y; diff
> [1] "2005-11-23 19:58:20 GMT"
> [1] "2005-11-23 20:58:20 GMT"
> Time difference of 1 hours
> > y-diff
> [1] "2005-11-23 20:58:19 GMT"
> Warning message:
> Incompatible methods ("-.POSIXt", "Ops.difftime") for "-"
>
> Do I have the syntax wrong? Or is some conversion of the difftime
> object to raw seconds necessary prior to performing arithmetic? And
> is the help page wrong?
>
> Thanks.
>
> Franklin
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Dec 01 07:04:41 2005

This archive was generated by hypermail 2.1.8 : Thu 01 Dec 2005 - 09:33:12 EST