[R] How to deal with thousands of seconds in R?

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Oct 9 14:51:24 CEST 2012

On 09/10/2012 09:54, Agustin Lobo wrote:
> If I do:
>> a
> [1] "2012_10_01_14_13_32.445"
>> a2
> [1] "2012_10_01_14_13_32.500"
>> strptime(a,format="%Y_%M_%d_%H_%M_%S")-strptime(a2,format="%Y_%M_%d_%H_%M_%S")
> Time difference of 0 secs
> Is there any time object in R that would deal with thousands of seconds?

Did you mean milliseconds, that is 1/1000th of a second?  If so, see the 
help for the function you used:

      ‘%S’ Second as decimal number (00-61), allowing for up to two
           leap-seconds (but POSIX-compliant implementations will ignore
           leap seconds).

      Specific to R is ‘%OSn’, which for output gives the seconds
      truncated to ‘0 <= n <= 6’ decimal places (and if ‘%OS’ is not
      followed by a digit, it uses the setting of
      ‘getOption("digits.secs")’, or if that is unset, ‘n = 3’).
      Further, for ‘strptime’ ‘%OS’ will input seconds including
      fractional seconds.  Note that ‘%S’ ignores (and not rounds)
      fractional parts on output.

Time difference of -0.05500007 secs

(Note that a is not a binary fraction, so some representation error is 

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