[R] Incompatible methods ("-.POSIXt", "Ops.difftime") for "-"

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Oct 8 18:21:33 CEST 2007


On Mon, 8 Oct 2007, Albrecht, Dr. Stefan (APEP) wrote:

> Dear all,
>
> according to the Help-page of DateTimeClasses {base} I should be able to do
>
> time - z
>
> with
>
> time 	date-time objects
> z 	a numeric vector (in seconds) or an object of class "difftime".
>
> However, on R version 2.6.0 (Windows XP) I get
>> Sys.time() - as.difftime(c("0:3:20", "11:23:15"))
> Time differences in mins
> [1] 1191837998 1191837318
> attr(,"tzone")
> [1] ""
> Warning message:
> Incompatible methods ("-.POSIXt", "Ops.difftime") for "-"
>
>
> This works, on the other hand:
>> Sys.time() - as.numeric(as.difftime(c("0:3:20", "11:23:15")))
> [1] "2007-10-08 12:16:18 Westeuropäische Normalzeit" "2007-10-08 12:04:58 Westeuropäische Normalzeit"
>
>
> Am I understanding something wrongly?

No, that currently does not work (it did when the page was written).
This does

Sys.time() - unclass(as.difftime(c("0:3:20", "11:23:15")))

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list