正在将.dat文件导入R控制台。希望得到一个干净的表,这样我就可以把它转换回CSV,并在Excel中操作其他CSV文件。
下面是整个R控制台会话。该表在控制台中看起来是对齐的,但导出到CSV时肯定不是对齐的。试一试代码,看看会发生什么。
sun <- readLines("http://www1.ncdc.noaa.gov/pub/data/ccd-data/pctpos15.dat")
head(sun)
sun <- read.table("http://www1.ncdc.noaa.gov/pub/data/ccd-data/pctpos15.dat", header=TRUE, sep=',')
Warning messages:
1: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
EOF within quoted string
2: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
number of items read is not a multiple of the number of columns
sun <- read.table("http://www1.ncdc.noaa.gov/pub/data/ccd-data/pctpos15.dat", header=TRUE, sep=' ')
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
line 1 did not have 87 elements
sun <- read.table("http://www1.ncdc.noaa.gov/pub/data/ccd-data/pctpos15.dat", header=TRUE)
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
line 9 did not have 15 elements
sun <- read.csv("http://www1.ncdc.noaa.gov/pub/data/ccd-data/pctpos15.dat", header=TRUE)
sundf <- data.frame(sun)
write.csv(sundf, "sun.csv")第二次尝试:
sun <- read_fwf("http://www1.ncdc.noaa.gov/pub/data/ccd-data/pctpos15.dat", col_positions = fwf_positions())
Error in stopifnot(length(start) == length(end)) :
argument "start" is missing, with no default发布于 2016-04-28 21:30:30
这样做效果很好:
sun <- read_table("http://www1.ncdc.noaa.gov/pub/data/ccd-data/pctpos15.dat")https://stackoverflow.com/questions/36869347
复制相似问题