如何创建时间序列数组

发布于 2025-01-01 22:54:00 字数 763 浏览 2 评论 0原文

我有几百个数据文件,每个文件包含一个 3 行标题和一列采样数据值。标头中有多个字段,其中包括一个时间字段,该字段给出文件的创建时间,例如 "Time=10:00:00.156"、采样时间 "Tsamp=0.1000" 和 "TimeUnits=1.0000E-06" (即文件中数据值之间的时间间隔 = 0.1 微秒)。我想使用此信息为文件中每个获取的数据值创建时间向量。

我该怎么做?我尝试了 chron 和 Zoo 库以及不同的 ts 函数,但无法做到。任何帮助将不胜感激。

我希望能够将其放入脚本中,以便我可以自动处理所有文件。我最终想要得到的是一个包含两列的数据框,显示第 1 列中所有上述文件的串联时间以及第 2 列中所有上述文件的串联测量值。

ATF v1.00 Date=23-01-2012; 
Time=10:38:56.421000; 
TracePoints=16384; 
TSamp=0.100000; 
TimeUnits=1.00000e-006; 
AmpToVolts=1.0000;
TraceMaxVolts=0.10000; 
PTime=0.00000; 
STime=0.00000; 
[TraceData] 
 4.82178e-004 
-1.37329e-003 
2.19116e-003 
4.38843e-003 
1.65405e-003 
3.36304e-003 
5.95093e-003 
2.19116e-003

再次,任何帮助将不胜感激。

I have a few hundred data files, each comprising of a 3 line header and a single column of sampled data values. In the header there is are multiple fields including a time field which gives the time the file was created e.g. "Time=10:00:00.156", sampling time "Tsamp=0.1000" and "TimeUnits=1.0000E-06" (i.e. time interval between data values in file = 0.1 microSeconds). I want to use this information to create a vector of times for each of the acquired data values in the file.

How can I do this? I tried chron and zoo libraries and the differnt ts functions but couldn't do it. Any help would be sincerely appreciated.

I would like to be able to put this into a script so that I can process all the files automatically. what I would like to end up with is a data frame with two columns showing the concatenated times for all of the above files in column 1 and the concatenated measured values for all of the above files in column 2.

ATF v1.00 Date=23-01-2012; 
Time=10:38:56.421000; 
TracePoints=16384; 
TSamp=0.100000; 
TimeUnits=1.00000e-006; 
AmpToVolts=1.0000;
TraceMaxVolts=0.10000; 
PTime=0.00000; 
STime=0.00000; 
[TraceData] 
 4.82178e-004 
-1.37329e-003 
2.19116e-003 
4.38843e-003 
1.65405e-003 
3.36304e-003 
5.95093e-003 
2.19116e-003

Again any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

是伱的 2025-01-08 22:54:00

我编辑了您的问题以包含您在评论中输入的数据。使用 textConnection 与访问文件非常相似,但如果您首先使用 readLines 然后使用 read.table ,因为我不确定文件连接是否始终与文件上的这两个函数保持打开状态。我认为您无法将亚毫秒数据转换为 R 时间类,因为时间数据的精度因需要以毫秒分辨率表示数十年而消耗,并且尾数中没有足够的额外数字一个八字节的数字。 Zoo 包不需要时间作为索引,因此您可以自由使用序列号或“数字”时间刻度,而不是“时间”时间刻度。

txt <- textConnection("ATF v1.00 Date=23-01-2012; 
Time=10:38:56.421000; 
TracePoints=16384; 
TSamp=0.100000; 
TimeUnits=1.00000e-006; 
AmpToVolts=1.0000;
TraceMaxVolts=0.10000; 
PTime=0.00000; 
STime=0.00000; 
[TraceData] 
 4.82178e-004 
-1.37329e-003 
2.19116e-003 
4.38843e-003 
1.65405e-003 
3.36304e-003 
5.95093e-003 
2.19116e-003")

headers <- readLines(txt, n=9)
tracedat <- read.table(txt, header=TRUE)

closeAllConnections()

 headers
#-----------------
[1] "ATF v1.00 Date=23-01-2012; " "Time=10:38:56.421000; "     
[3] "TracePoints=16384; "         "TSamp=0.100000; "           
[5] "TimeUnits=1.00000e-006; "    "AmpToVolts=1.0000;"         
[7] "TraceMaxVolts=0.10000; "     "PTime=0.00000; "            
[9] "STime=0.00000; "      
# ----------      
tracedat
#-----------------
  X.TraceData.
1  0.000482178
2 -0.001373290
3  0.002191160
4  0.004388430
5  0.001654050
6  0.003363040
7  0.005950930
8  0.002191160

I edited your question to include the data you put in your comment. Using a textConnection is very similar to accessing a file, but you may need to use the skip option if you first usereadLines and then use read.table , since I'm not sure that the file connection will always be kept open with those two functions on a file. I do not think you will be able to convert the sub-millisecond data to R time classes, since the precision of time data is consumed by the need to represent decades on a millisecond resolution and there just are not enough extra digits in the mantissa of an eight byte number. The zoo package does not require time as the index so you are free to use either sequence number or a "numeric" time scale rather than a 'time" time scale.

txt <- textConnection("ATF v1.00 Date=23-01-2012; 
Time=10:38:56.421000; 
TracePoints=16384; 
TSamp=0.100000; 
TimeUnits=1.00000e-006; 
AmpToVolts=1.0000;
TraceMaxVolts=0.10000; 
PTime=0.00000; 
STime=0.00000; 
[TraceData] 
 4.82178e-004 
-1.37329e-003 
2.19116e-003 
4.38843e-003 
1.65405e-003 
3.36304e-003 
5.95093e-003 
2.19116e-003")

headers <- readLines(txt, n=9)
tracedat <- read.table(txt, header=TRUE)

closeAllConnections()

 headers
#-----------------
[1] "ATF v1.00 Date=23-01-2012; " "Time=10:38:56.421000; "     
[3] "TracePoints=16384; "         "TSamp=0.100000; "           
[5] "TimeUnits=1.00000e-006; "    "AmpToVolts=1.0000;"         
[7] "TraceMaxVolts=0.10000; "     "PTime=0.00000; "            
[9] "STime=0.00000; "      
# ----------      
tracedat
#-----------------
  X.TraceData.
1  0.000482178
2 -0.001373290
3  0.002191160
4  0.004388430
5  0.001654050
6  0.003363040
7  0.005950930
8  0.002191160
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文