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:
3开发者_JS百科4201881666,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.
Here is what I would do:
- Create an 'anchor' timestamp of midnight using, e.g
ISOdatetime()
. Keep asPOSIXct
, or convert usingas.numeric()
. - Add you microseconds-since-midnight to it, properly scaled.
- 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>
精彩评论