Try comment.char="Y"
which will make read.table
ignore all the lines starting with Y
.
stringsAsFactors=FALSE
will avoid converting strings to factors.
inp <- read.table("MAXT1969.TXT", skip = 1, header=FALSE, comment.char="Y", stringsAsFactors=FALSE )
#Read just first row to get header names
cols <- read.table("MAXT1969.TXT", header=FALSE, skip=1, nrows=1 )
names(inp) <- cols
inp
## YEAR DAY MT DT LAT. 66.5 67.5 68.5 69.5 70.5
## 1 1969 1 1 1 6.5 99.9 99.9 31.9 99.9 99.9
## 2 1969 1 1 1 7.5 99.9 20.9 99.9 99.9 23.9
## 3 1969 1 1 1 8.5 99.9 99.9 30.9 99.9 18.9
## 4 1969 1 1 2 6.5 21.9 99.9 99.9 99.9 99.9
## 5 1969 1 1 2 7.5 99.9 33.9 99.9 99.9 99.9
## 6 1969 1 1 2 8.5 99.9 99.9 15.9 99.9 99.9
## 7 1969 1 1 3 6.5 99.9 99.9 99.9 99.9 99.9
## 8 1969 1 1 3 7.5 99.9 99.9 99.9 99.9 99.9
## 9 1969 1 1 3 8.5 99.9 99.9 99.9 99.9 99.9
#Since the stringsAsFactor = FALSE was used numbers were read correctly.
inp[1, 5]
## [1] 6.5