vroom使用空格delim错误地分析列

wko9yo5t  于 2023-03-27  发布在  其他
关注(0)|答案(1)|浏览(146)

我试着用vroom读取一些空格分隔的数据,大约一年前,这个方法可以给出11列数字数据:

library(vroom)
fname <- "http://berkeleyearth.lbl.gov/auto/Global/Complete_TAVG_complete.txt"
dat <- vroom(file = fname, delim = " ", col_names = FALSE, comment = "%", na = "NaN")

现在我在dat中得到了58列,大部分是空逻辑,这是白色的编码问题吗?
下面是sessionInfo()

R version 4.2.2 (2022-10-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.7.4

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] vroom_1.6.1
p5cysglq

p5cysglq1#

它看起来像一个固定宽度的文件,所以分隔符不起作用。使用vroom::vroom_fwf()

url = "http://berkeleyearth.lbl.gov/auto/Global/Complete_TAVG_complete.txt"
f = tempfile()
download.file(url, f)
on.exit(unlink(f))
dat = vroom::vroom_fwf(f, skip = 35)

相关问题