I have some trouble importing a text file seperated by space / multiple spaces that also contains columns with strings that have spaces that should not be interpreted as seperators!
The table has no column names and a maximum of 9 columns. Column 6 is cmoprised by a string with spaces in it. Columns 4, 7, 8, 9 are optional and partly missing.
My idea was to use the fixed column widths when reading the table but was technically not able to achieve this..
Here is the file-url: ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily/ghcnd-stations.txt
Because read.table throws an error,
> read.table("ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily/ghcnd-stations.txt",sep="")
Fehler in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
Zeile 1 hatte keine 9 Elemente
I did this instead
lines <- readLines("ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily/ghcnd-stations.txt")
Here's a sample of lines
:
a <- c("USC00080211 29.7258 -85.0206 6.1 FL APALACHICOLA AIRPORT HCN 72220",
"USC00080228 27.2181 -81.8739 9.1 FL ARCADIA HCN ",
"USC00080236 27.1819 -81.3508 42.7 FL ARCHBOLD BIO STN ",
"USC00080369 27.5947 -81.5267 46.9 FL AVON PARK 2 W ",
"USC00080374 27.6000 -81.5000 46.0 FL AVON PARK 1 NW ",
"USC00080390 27.8500 -81.5167 38.1 FL BABSON PARK 1 ENE ",
"USC00080414 24.6589 -81.2761 0.9 FL BAHIA HONDA SP ",
"USC00080478 27.8986 -81.8433 38.1 FL BARTOW HCN ",
"ACW00011604 17.1167 -61.7833 10.1 ST JOHNS COOLIDGE FLD ",
"ACW00011647 17.1333 -61.7833 19.2 ST JOHNS ",
"AE000041196 25.3330 55.5170 34.0 SHARJAH INTER. AIRP GSN 41196"
)
tf <- tempfile(fileext=".txt")
writeLines(a,tf)
shell.exec(tf)
#read.table(tf, sep = "", ??)