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
"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.
preguntado el 02 de febrero de 12 a las 11:02
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 use
readLines Y luego usar
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 #-----------------  "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; " # ---------- 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