3
votes

in a CSV file I have a few columns. One column has timestamps, where each stamp is the microseconds passed midnight of today (each csv file only have data within a day), so this is not ambiguous.

My question is, how do I parse these microseconds time stamps into R? thanks a lot!

part of my CSV file:

34201881666,250,10.8,2612,10.99,11,460283,11.01,21450,,,,,
34201883138,23712,10.02,562,10.03,10.04,113650,11,460283,,,,,
34201883138,23712,10.02,562,10.03,10.04,113650,10.05,57811,,,,,

The first column is the time stamps (the microseconds passed midnight of today). I want to construct a time series, for example in xts package, so that the time stamps of that series is from the first column.

1
You need to post an example and describe what you hope to do with this information. Some of the DateTime classes are limited to millisecond resolution.IRTFM
Resolution is OS-dependent. On Linux you get microseconds.Dirk Eddelbuettel

1 Answers

6
votes

Here is what I would do:

  1. Create an 'anchor' timestamp of midnight using, e.g ISOdatetime(). Keep as POSIXct, or convert using as.numeric().
  2. Add you microseconds-since-midnight to it, properly scaled.
  3. Convert to POSIXct (if needed), and you're done.

Quick example using your first three timestamps:

R> ISOdatetime(2011,8,2,0,0,0) + c(34201881666, 34201883138, 34201883138)*1e-6
[1] "2011-08-02 09:30:01.881665 CDT" "2011-08-02 09:30:01.883137 CDT" 
[3] "2011-08-02 09:30:01.883137 CDT"
R>