将不完整的 .dat 文件加载到 R
Load incomplete .dat file into R
我的数据来自这个 URL 并且具有以下结构:
93193KFAT FAT2013123016150015 NP [0000 ] 0.00 39999 29.791
93193KFAT FAT2013123016160016 NP [0000 ] 0.00 39999 29.791
93193KFAT FAT2013123016170017 NP [0000 ] 39999 29.791
93193KFAT FAT2013123016170017 NP [0000 ] 0.00 39999 29.791
所以如果你看到这个:
- 数据以空格分隔,
- 缺少一些列条目(即第 3 行中的 0.00)。
当我将其加载到 R 中时,出现以下错误:
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
line 377 did not have 12 elements
你如何解决这个问题?这样我就可以直接从 URL 打开它而不会有任何问题?
谢谢!
> read.fwf(ftp://ftp.ncdc.noaa.gov/pub/data/asos-onemin/6406-2013/64060KFAT201312.dat)
Error: unexpected '/' in "read.fwf(ftp:/"
trying URL 'ftp://ftp.ncdc.noaa.gov/pub/data/asos-onemin/6406- 2013/64060KFAT201312.dat'
using Synchronous WinInet calls
Error in download.file(url, downloadPath) :
cannot open URL 'ftp://ftp.ncdc.noaa.gov/pub/data/asos-onemin/6406-2013/64060KFAT201312.dat'
In addition: Warning message:
In download.file(url, downloadPath) : InternetOpenUrl failed: ''
Error in download.file(url, downloadPath) : unsupported URL scheme
1) 尝试 url("...")。我收到错误:
Error in url("ftp.ncdc.noaa.gov/pub/data/asos-onemin/6406-2013/64060KFAT201312.dat") :
unsupported URL scheme
2) 我尝试使用库 (RCurl) 并执行:getURL("...)。我收到错误消息:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file [... and R shows the data in the url ]
大致如下:
a <- read.fwf("ftp://ftp.ncdc.noaa.gov/pub/data/asos-onemin/6406-2013/64060KFAT201312.dat",
widths=c(9, 20, 2, 3, 9, 5, 6, 7))
我的数据来自这个 URL 并且具有以下结构:
93193KFAT FAT2013123016150015 NP [0000 ] 0.00 39999 29.791
93193KFAT FAT2013123016160016 NP [0000 ] 0.00 39999 29.791
93193KFAT FAT2013123016170017 NP [0000 ] 39999 29.791
93193KFAT FAT2013123016170017 NP [0000 ] 0.00 39999 29.791
所以如果你看到这个:
- 数据以空格分隔,
- 缺少一些列条目(即第 3 行中的 0.00)。
当我将其加载到 R 中时,出现以下错误:
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
line 377 did not have 12 elements
你如何解决这个问题?这样我就可以直接从 URL 打开它而不会有任何问题?
谢谢!
> read.fwf(ftp://ftp.ncdc.noaa.gov/pub/data/asos-onemin/6406-2013/64060KFAT201312.dat)
Error: unexpected '/' in "read.fwf(ftp:/"
trying URL 'ftp://ftp.ncdc.noaa.gov/pub/data/asos-onemin/6406- 2013/64060KFAT201312.dat'
using Synchronous WinInet calls
Error in download.file(url, downloadPath) :
cannot open URL 'ftp://ftp.ncdc.noaa.gov/pub/data/asos-onemin/6406-2013/64060KFAT201312.dat'
In addition: Warning message:
In download.file(url, downloadPath) : InternetOpenUrl failed: ''
Error in download.file(url, downloadPath) : unsupported URL scheme
1) 尝试 url("...")。我收到错误:
Error in url("ftp.ncdc.noaa.gov/pub/data/asos-onemin/6406-2013/64060KFAT201312.dat") :
unsupported URL scheme
2) 我尝试使用库 (RCurl) 并执行:getURL("...)。我收到错误消息:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file [... and R shows the data in the url ]
大致如下:
a <- read.fwf("ftp://ftp.ncdc.noaa.gov/pub/data/asos-onemin/6406-2013/64060KFAT201312.dat",
widths=c(9, 20, 2, 3, 9, 5, 6, 7))