我正在尝试使用 read.table 函数为 sp 加载 CRAN 数据集,但是我不知道我是否可以访问数据

I am trying to load a CRAN dataset for sp using the read.table function, however I do not know if I have access to the data

我正在按照书中的示例进行操作 "Spatial Analysis with R"。我已经加载了 sp 包,我正在尝试使用以下方法读取 table:

 Cran_df<-read.table("CRAN051001a.txt", header = TRUE)

我收到错误:

 Error in file(file, "rt") : cannot open the connection
 In addition: Warning message:
 In file(file, "rt") :
 cannot open file 'CRAN051001a.txt': No such file or directory

如何获取本练习所需的数据?

通过使用完整的 URL:

Cran_df<-read.table("http://www.asdar-book.org/datasets/CRAN051001a.txt", header = TRUE)

现在你的对象 Cran_df 应该没问题了:

str(Cran_df)

'data.frame':   54 obs. of  6 variables:
$ place: Factor w/ 52 levels "Aalborg","Aizu",..: 9 31 50 15 49 39 36 40 12 46 ...
$ north: Factor w/ 52 levels "20d45'S","22d43'S",..: 8 18 41 7 1 3 2 4 43 29 ...
$ east : Factor w/ 51 levels "0d10'W","118d15'W",..: 19 16 20 35 31 32 34 33 11 39 ...
$ loc  : Factor w/ 30 levels "Australia","Austria",..: 1 1 2 3 3 3 3 3 4 19 ...
$ long : num  153 145 16.3 -49.3 -42.9 ...
$ lat  : num  -27.5 -37.8 48.2 -25.4 -20.8 ...