[Rd] diff(time) vs. difftime?

From: Spencer Graves <spencer.graves_at_structuremonitoring.com>
Date: Mon, 19 Mar 2012 15:27:10 -0700

       I just encountered another RTFM problem: With diff(as.POSIXct(...), ...) I was unable to control the units of the results. Examples:

> (d.d <- diff(as.POSIXct(c('2012-12-12', '2012-12-13'))))
Time difference of 1 days
> (d.h <- diff(as.POSIXct(c('2012-12-12 08:00', '2012-12-12 09:00'))))
Time difference of 1 hours
> (d.m <- diff(as.POSIXct(c('2012-12-12 08:00', '2012-12-12 08:01'))))
Time difference of 1 mins
> (d.s <- diff(as.POSIXct(c('2012-12-12 08:00:00', '2012-12-12
Time difference of 1 secs
> as.numeric(d.d)

[1] 1
> as.numeric(d.s)

[1] 1

       methods('diff') identified the following:

[1] diff.Date diff.default diff.POSIXt diff.ts diff.zoo*

       In looking at the help pages for each of these functions, I found no mention of "difftime" or any other way to control the units.

[1] -.Date -.POSIXt -.yearmon* -.yearqtr*

        ?"-.Date" didn't seem helpful on this, either. ?"-.POSIXt" contained a link to "difftime", but I didn't see that until after I read the code for "-.POSIXt" and found "difftime".

       I humbly beseech ye to consider adding a difftime example to all these help pages.


p.s. In case there is any doubt, I very much appreciate all the work that the R Core team has invested in making R what it is today.

Spencer Graves, PE, PhD
President and Chief Technology Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San Josť, CA 95126
ph:  408-655-4567
web:  www.structuremonitoring.com

R-devel_at_r-project.org mailing list
Received on Mon 19 Mar 2012 - 22:30:48 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 20 Mar 2012 - 02:50:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive