[R] How to deal with thousands of seconds in R?
Agustin Lobo
Agustin.Lobo at ictja.csic.es
Tue Oct 9 16:17:28 CEST 2012
Sorry for the typo, I meant thousandths, and thanks for pointing out
the %OS format, which I had overlooked
Agus
On Tue, Oct 9, 2012 at 2:51 PM, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> 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.
>
> 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.)
>
> --
> 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
--
--
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
e-mail Agustin.Lobo at ictja.csic.es
https://sites.google.com/site/aloboaleu/
More information about the R-help
mailing list