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 7680507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:07:46+00:00 2026-05-31T18:07:46+00:00

It looks like POSIXlt allows millisecond precision specification, but I have a problem when

  • 0

It looks like POSIXlt allows millisecond precision specification, but I have a problem when setting a .001 millisecond index value in an xts object:

> options(digits.secs = 3)
> data(sample_matrix)
> sample.xts = xts(sample_matrix, rep(as.POSIXlt("2012-03-20 09:02:50.001"), 180))
> head(sample.xts, 10)
                            Open     High      Low    Close
2012-03-20 09:02:50.000 50.03978 50.11778 49.95041 50.11778
2012-03-20 09:02:50.000 50.23050 50.42188 50.23050 50.39767
2012-03-20 09:02:50.000 50.42096 50.42096 50.26414 50.33236
2012-03-20 09:02:50.000 50.37347 50.37347 50.22103 50.33459
2012-03-20 09:02:50.000 50.24433 50.24433 50.11121 50.18112
2012-03-20 09:02:50.000 50.13211 50.21561 49.99185 49.99185
2012-03-20 09:02:50.000 50.03555 50.10363 49.96971 49.98806
2012-03-20 09:02:50.000 49.99489 49.99489 49.80454 49.91333
2012-03-20 09:02:50.000 49.91228 50.13053 49.91228 49.97246
2012-03-20 09:02:50.000 49.88529 50.23910 49.88529 50.23910
> sample.xts = xts(sample_matrix, rep(as.POSIXlt("2012-03-20 09:02:50.002"), 180))
> head(sample.xts, 10)
                            Open     High      Low    Close
2012-03-20 09:02:50.002 50.03978 50.11778 49.95041 50.11778
2012-03-20 09:02:50.002 50.23050 50.42188 50.23050 50.39767
2012-03-20 09:02:50.002 50.42096 50.42096 50.26414 50.33236
2012-03-20 09:02:50.002 50.37347 50.37347 50.22103 50.33459
2012-03-20 09:02:50.002 50.24433 50.24433 50.11121 50.18112
2012-03-20 09:02:50.002 50.13211 50.21561 49.99185 49.99185
2012-03-20 09:02:50.002 50.03555 50.10363 49.96971 49.98806
2012-03-20 09:02:50.002 49.99489 49.99489 49.80454 49.91333
2012-03-20 09:02:50.002 49.91228 50.13053 49.91228 49.97246
2012-03-20 09:02:50.002 49.88529 50.23910 49.88529 50.23910

Why the 001 millisecond setting fails?

  • 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-05-31T18:07:48+00:00Added an answer on May 31, 2026 at 6:07 pm

    I suspect this is a rounding/floating point issue:

    Browse[2]> print(head(as.numeric(order.by)), digits = 20)
    [1] 1332234170.0009999275 1332234170.0009999275 1332234170.0009999275
    [4] 1332234170.0009999275 1332234170.0009999275 1332234170.0009999275
    

    That was achieved by debugging xts() on a the call

    foo <- xts(1:180, rep(as.POSIXlt("2012-03-20 09:02:50.001"), 180), 
               unqiue = FALSE)
    

    but you can see the problem via clearly via

    > print(as.numeric(as.POSIXlt("2012-03-20 09:02:50.001")))
    [1] 1332234170
    > print(as.numeric(as.POSIXlt("2012-03-20 09:02:50.001")), digits = 20)
    [1] 1332234170.0009999275
    

    Indicating your fractional number of seconds can’t be created nor stored at exactly .001 milliseconds. Whereas truncation as 3 dp will keep .002 as it is stored as:

    > print(as.numeric(as.POSIXlt("2012-03-20 09:02:50.002")), digits = 20)
    [1] 1332234170.0020000935
    

    Truncating or rounding that to 3 dp will preserve the .002 part. One of the issues you have to deal with in working with computers.

    Do note that this appears to just be an issue in the printed representation of the index dates:

    > print(as.numeric(index(foo)[1]), digits = 20)
    [1] 1332234170.0009999275
    

    The precision (with floating point issues) is preserved in the actual object storing the index times – you just can’t see that when printing the times to the console.

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

Sidebar

Related Questions

Looks like others have had this problem but I can't seem to find a
Looks like other people have had this issue, but I would like to understand
Looks like operator new and operator new[] have exactly the same signature: void* operator
Looks like I've missed something obvious but really can't figure out why I can't
looks like heroku is using npm version 1.0.94 I have a dependency that require
Looks like linux doesnt implement pthread_suspend and continue, but I really need em. I
I have a df/zoo/xts/whatever that is split by day of week. I'd like to
Looks like stupid question, but I just dont get it. My entity: public class
Looks like a stupid question. But comment to my answer to one of the
Looks like the following Ellipse in ControlTemplate does not get the BorderThickness, but why?

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.