1

R のプロジェクトで複数のシェープファイルを操作する必要があります。

したがって、これらのファイルをリストにロードするために readOGR 関数を繰り返したいと思います。後で、plyr を使用するか、ループを作成して、リスト内のすべてのシェープファイルに対して同じ操作を実行できます。

最小限の再現可能な例を次に示します。

library("rgdal")

setwd("your.path.here")
download.file("http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_countries.zip","ne_10m_admin_0_countries.zip")

unzip("ne_10m_admin_0_countries.zip")

# works like this:
my.shapefile<-readOGR("your.path.here","ne_10m_admin_0_countries")
plot(my.shapefile)

# does not work like this
shapefile.list<-list(length=20)
shapefile.list[1]<-readOGR("your.path.here","ne_10m_admin_0_countries")

plot(shapefile.list[1])

エラーメッセージは

Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y'
4

1 に答える 1

1

単一の角括弧は、リストをサブセット化するためのものです。二重角括弧は、リストの要素を取得および設定するためのものです。

したがって、二重角かっこを使用します。デモ:

> a=list(1,2,3,4)

a[2]1 つの要素を持つリストです。

> a[2]
[[1]]
[1] 2

a[[2]]はまさにその要素です:

> a[[2]]
[1] 2
于 2014-03-27T13:12:06.317 に答える