I have a water balance text file of which first 20 lines are not necessary for analysis. Then I have a column names line which I want to preserve and again a line with units and then hyphens I want to ignore. Then I have the data which I want to get right after column names. There are 17 lines of unnecessary data before the column names line and the file generally looks like below:
Unnecessary lines
Unnecessary lines
Unnecessary lines
Unnecessary lines
Unnecessary lines
Unnecessary lines
---------------------------------------
Column_names Column_names Column_names
unit unit unit
---------------------------------------
Data Data Data
Data Data Data
Data Data Data
Data Data Data
First, I thought I will use read. table and skip lines above column names and just delete the rows with hyphens below but always got an error called "Error in the scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 1 did not have 20 elements"
So far i have tried:
data1 <- read.table("2_wat.txt", skip = 17, sep = '\t')
If I do following I get the data but lose column names
data1 <- read.table("2_wat.txt", skip = 22)
If anyone has suggestions for then I will greatly appreciate your help.