0

I have some .txt file with different size of headings. I only need numbers from Column01 to Column18. How to read them? Approach from Read in multiple .txt files with header in R don't work for me.

POM01.DEF


Timeplot
Column01: V RMS L1 [V]
Column02: V RMS L2 [V]
Column03: V RMS L3 [V]
Column04: I RMS L1 [A]
Column05: I RMS L2 [A]
Column06: I RMS L3 [A]
Column07: P L1 [W]
Column08: P L2 [W]
Column09: P L3 [W]
Column10: P Sum [W]
Column11: Q L1 [VAr]
Column12: Q L2 [VAr]
Column13: Q L3 [VAr]
Column14: Q Sum [VAr]
Column15: PF L1 [1]
Column16: PF L2 [1]
Column17: PF L3 [1]
Column18: PF Sum [1]

Time                         Column01    Column02    Column03    Column04    Column05    Column06    Column07    Column08    Column09    Column10    Column11    Column12    Column13    Column14    Column15    Column16    Column17    Column18
18.03.2009 13:20:00             5762,2      5111,9      4338,7      197,20      214,69      219,80     0,43e+3   110,40e+3     0,00e+3   0,1108e+6    -1,73e+3   -70,50e+3     0,00e+3   -72,22e+3    -0,00038    -0,10060     0,00000    -0,03477
18.03.2009 13:30:00             8988,6      9156,5      9125,4       19,86       40,60       14,53    46,63e+3   252,66e+3    25,93e+3   0,3252e+6   -41,32e+3  -245,37e+3   -22,70e+3  -309,39e+3    -0,26123    -0,67965    -0,19553    -0,47625
Kulis
  • 988
  • 3
  • 11
  • 25
  • 2
    You could use `readLines/read.table` i.e. `lines <- readLines('Kulis.txt');ind <- grep('\\d{2}\\.\\d{2}.', lines)[1]-1; lines1 <- lines[ind:length(lines)]; lines1[-1] <- gsub('^|(?<=:\\d{2}) ', "'", lines1[-1], perl=TRUE);read.table(text=lines1, header=TRUE, dec=",")` – akrun May 02 '15 at 19:40

1 Answers1

2

this is similar to @akrun

wh <- grep('\\bTime\\b', rl <- readLines('~/desktop/tmp.txt'))
rl <- gsub('\\s{2,}', ';', rl[wh:length(rl)])

read.table(text = rl, header = TRUE, sep = ';', dec = ',')


#                  Time Column01 Column02 Column03 Column04 Column05 Column06 Column07 Column08 Column09 Column10 Column11 Column12 Column13 Column14 Column15 Column16 Column17 Column18
# 1 18.03.2009 13:20:00   5762.2   5111.9   4338.7   197.20   214.69   219.80      430   110400        0   110800    -1730   -70500        0   -72220 -0.00038 -0.10060  0.00000 -0.03477
# 2 18.03.2009 13:30:00   8988.6   9156.5   9125.4    19.86    40.60    14.53    46630   252660    25930   325200   -41320  -245370   -22700  -309390 -0.26123 -0.67965 -0.19553 -0.47625
rawr
  • 20,481
  • 4
  • 44
  • 78