Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8048461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:26:47+00:00 2026-06-05T06:26:47+00:00

Given the following issue with rounding milliseconds under R. How do I get around

  • 0

Given the following issue with rounding milliseconds under R. How do I get around it so that the times are correct?

> options(digits.secs=3)
> as.POSIXlt("13:29:56.061", format='%H:%M:%OS', tz='UTC')
[1] "2012-06-07 13:29:56.060 UTC"
> as.POSIXlt("13:29:56.062", format='%H:%M:%OS', tz='UTC')
[1] "2012-06-07 13:29:56.061 UTC"
> as.POSIXlt("13:29:56.063", format='%H:%M:%OS', tz='UTC')
[1] "2012-06-07 13:29:56.063 UTC"

I noticed that this URL provides background information but doesn’t solve my issue:
Milliseconds puzzle when calling strptime in R.

Also this URL touches on the issue but doesn’t solve it: R xts: .001 millisecond in index.

In these cases I do see the following:

> x <- as.POSIXlt("13:29:56.061", format='%H:%M:%OS', tz='UTC')
> print(as.numeric(x), digits=20)
[1] 1339075796.0610001087

The URL also seems to indicate that this is just a display issue but I’ve noticed that using statements like "%OS3" without the options line don’t seem to pickup the correct number of digits.

The version I’m using is 32 bit 2.15.0 under Windows but this seems to exist under other situations for R.

Note that my original data is these date time strings within a CSV file I must find a way of converting them into the correct millisecond time from a string.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:26:50+00:00Added an answer on June 5, 2026 at 6:26 am

    I don’t see that:

    > options(digits.secs = 4)
    > as.POSIXlt("13:29:56.061", format = '%H:%M:%OS', tz='UTC')
    [1] "2012-06-07 13:29:56.061 UTC"
    > as.POSIXlt("13:29:56.062", format = '%H:%M:%OS', tz='UTC')
    [1] "2012-06-07 13:29:56.062 UTC"
    > as.POSIXlt("13:29:56.063", format = '%H:%M:%OS', tz='UTC')
    [1] "2012-06-07 13:29:56.063 UTC"
    > options(digits.secs = 3)
    > as.POSIXlt("13:29:56.061", format = '%H:%M:%OS', tz='UTC')
    [1] "2012-06-07 13:29:56.061 UTC"
    > as.POSIXlt("13:29:56.062", format = '%H:%M:%OS', tz='UTC')
    [1] "2012-06-07 13:29:56.062 UTC"
    > as.POSIXlt("13:29:56.063", format = '%H:%M:%OS', tz='UTC')
    [1] "2012-06-07 13:29:56.063 UTC"
    

    with

    > sessionInfo()
    R version 2.15.0 Patched (2012-04-14 r59019)
    Platform: x86_64-unknown-linux-gnu (64-bit)
    
    locale:
     [1] LC_CTYPE=en_GB.utf8       LC_NUMERIC=C             
     [3] LC_TIME=en_GB.utf8        LC_COLLATE=en_GB.utf8    
     [5] LC_MONETARY=en_GB.utf8    LC_MESSAGES=en_GB.utf8   
     [7] LC_PAPER=C                LC_NAME=C                
     [9] LC_ADDRESS=C              LC_TELEPHONE=C           
    [11] LC_MEASUREMENT=en_GB.utf8 LC_IDENTIFICATION=C      
    
    attached base packages:
    [1] stats     graphics  grDevices utils     datasets  methods  
    [7] base
    

    With the "%OSn" format strings, one forces truncation. If the fractional second cannot be represented exactly in floating points then the truncation may very well go the wrong way. If you see things going to wrong way you can also round explicitly to the unit you want or add a half of the fraction you wish to operate at (in the case shown 0.0005):

    > t1 <- as.POSIXlt("13:29:56.061", format = '%H:%M:%OS', tz='UTC')
    > t1
    [1] "2012-06-07 13:29:56.061 UTC"
    > t1 + 0.0005
    [1] "2012-06-07 13:29:56.061 UTC"
    

    (but a I said, I don’t see the problem here.)

    This latter point was made by Simon Urbanek on the R-Devel mailing list on 30-May-2012.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this bug (Python Issue 4892) that gives rise to the following error: >>>
Given certain multibyte character sets, am I correct in assuming that the following doesn't
I have an odd linq subquery issue. Given the following data structure: Parents Children
I'm trying to think of a fast algorithm for the following issue. Given a
Given the following code, How would you refactor this so that the method search_word
Given the following code (it's a macro that generates code for a list data
I'm running into the following issue: Given various numbers like: 10.38 11.12 5.24 9.76
I have an issue when sorting dates using jqGrid . Given the following dates
What is the best way to approach the following issue? I am given a
I have a strange sorting issue with my models. Given the following: I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.