[R] strptime format = "%H:%M:%OS6"
David Winsemius
dwinsemius at comcast.net
Tue Feb 15 23:45:42 CET 2011
Oh. So the %OS<n> only works with format.POSIXct(), format.POXIXlt(),
and strftime(), but NOT strptime()?
> x <- "09:31:29.18761"
>
> y <- strptime(x, format = "%H:%M:%OS");
> y
[1] "2011-02-15 09:31:29"
> format(y, format = "%H:%M:%OS3")
[1] "09:31:29.188"
> strftime(y, format = "%H:%M:%OS3")
[1] "09:31:29.188"
Thanks, Jim;
David.
On Feb 15, 2011, at 5:07 PM, jim holtman wrote:
> According to the documentation, '%OS6' is only for output, not for
> conversion on input.
>
> Specific to R is %OSn, which for output gives the seconds 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.
>
>
>
> On Tue, Feb 15, 2011 at 11:39 AM, Sam Steingold <sds at gnu.org> wrote:
>> I read a dataset with times in them, e.g., "09:31:29.18761".
>> I then parse them:
>>> all$X.Time <- strptime(all$X.Time, format = "%H:%M:%OS6");
>> and get a vector of NAs (how do I check that except for a visual
>> inspection?)
>> then I do
>>> options("digits.secs"=6);
>>> all$X.Time <- strptime(all$X.Time, format = "%H:%M:%OS");
>> and it, apparently, works:
>>> all$X.Time[2]-all$X.Time[1]
>> Time difference of 5.12188 secs
>> so, why doesn't format = "%H:%M:%OS6" work as documented?
>>
>>
>> --
>> Sam Steingold (http://sds.podval.org/) on CentOS release 5.3 (Final)
>> http://dhimmi.com http://openvotingconsortium.org http://palestinefacts.org
>> http://honestreporting.com http://www.memritv.org http://camera.org
>> There are two kinds of egotists: 1) Those who admit it 2) The rest
>> of us
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list