R中的微秒时间戳 [英] microsecond time stamps in R
问题描述
在CSV文件中,我有几列。一列有时间戳记,其中每个戳记是今天午夜过去的微秒(每个csv文件仅在一天之内包含数据),因此这并不明确。
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.
我的问题是,如何将这些微秒级的时间戳解析为R?非常感谢!
My question is, how do I parse these microseconds time stamps into R? thanks a lot!
我的CSV文件的一部分:
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,,,,,
第一个列是时间戳(今天午夜过去的微秒)。我想构造一个时间序列,例如在xts包中,以便该序列的时间戳记来自第一列。
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.
推荐答案
这就是我要做的事情:
- 使用例如
ISOdatetime()
创建午夜的锚定时间戳。保持为POSIXct
,或使用as.numeric()
进行转换。 - 将其添加到午夜以来的微秒中,并进行适当缩放。
- 转换为POSIXct(如果需要),就可以完成。
- 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>
这篇关于R中的微秒时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!