Skip to content
Prev 307422 / 398498 Next

How to deal with thousands of seconds in R?

On 09/10/2012 09:54, Agustin Lobo wrote:
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.

strptime(a,format="%Y_%M_%d_%H_%M_%OS")-strptime(a2,format="%Y_%M_%d_%H_%M_%OS")
Time difference of -0.05500007 secs

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