-1

我有几百个数据文件,每个文件都包含一个 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

再次感谢任何帮助。

4

1 回答 1

0

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
于 2012-02-04T12:51:12.207 回答