I have an instrument that produces data files which contain a large amount of header information. I want to read many files in at a time and rbind
them together. To read these in successfully I have been using the following loop and skip to deal with the header information:
df <- c()
for (x in list.files(pattern="*.cnv", recursive=TRUE)) {
u <-read.table(x, skip=100)
df <- rbind(df, u)
}
Here is an example of what the datafile with 5 lines to skip looks like:
# Header information
# Header information
# Header information
# Header information
# Header information
*END*
0.571 26.6331 8.2733 103.145 0.0842 -0.000049 0.000e+00
0.576 26.6316 8.2756 103.171 0.3601 -0.000049 0.000e+00
0.574 26.6322 8.2744 103.157 0.3613 -0.000046 0.000e+00
The issue is that the number of lines to skip is dynamic and I would like to come up with a generalized solution. Fortunately, every file ends with this:
*END*
So my question is, how can I read in a file with the above that skips over all lines before and includes the *END*
line? This likely would take place before rbind
-ing them together.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…