[Rd] Adding difftime objects to POSIXt objects

Jeffrey Horner jeff.horner at vanderbilt.edu
Wed Feb 21 23:45:25 CET 2007


Jeffrey Horner wrote:
> Hello,
> 
> ?DateTimeClasses states that "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."
> 
> So, is the below expected behavior?
> 
>  > x <- Sys.time()
>  > x
> [1] "2007-02-21 16:19:56 CST"
>  > x + as.difftime("1","%H")
> [1] "2007-02-21 16:19:57 CST"
> Warning message:
> Incompatible methods ("+.POSIXt", "Ops.difftime") for "+"
> 
> "+.POSIXt" does behave as expected, though:
> 
>  > "+.POSIXt"(x,as.difftime("1","%H"))
> [1] "2007-02-21 17:19:56 CST"
> 
>  > R.version
>                 _
> platform       i686-pc-linux-gnu
> arch           i686
> os             linux-gnu
> system         i686, linux-gnu
> status         Under development (unstable)
> major          2
> minor          5.0
> year           2007
> month          01
> day            07
> svn rev        40398
> language       R
> version.string R version 2.5.0 Under development (unstable) (2007-01-07 
> r40398)

Oops! I thought I ran this on the latest revision, but the same behavior 
is exhibited in r40774:

 > x <- Sys.time()
 > x
[1] "2007-02-21 16:44:16 CST"
 > x + as.difftime("1","%H")
[1] "2007-02-21 16:44:17 CST"
Warning message:
Incompatible methods ("+.POSIXt", "Ops.difftime") for "+"
 > R.version
                _
platform       i686-pc-linux-gnu
arch           i686
os             linux-gnu
system         i686, linux-gnu
status         Under development (unstable)
major          2
minor          5.0
year           2007
month          02
day            21
svn rev        40774
language       R
version.string R version 2.5.0 Under development (unstable) (2007-02-21 
r40774)


Jeff
-- 
http://biostat.mc.vanderbilt.edu/JeffreyHorner



More information about the R-devel mailing list