[Rd] Adding difftime objects to POSIXt objects

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


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)

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



More information about the R-devel mailing list