2017-05-03 5 views
0

mat2listw{spdep}を使用して、後で空間回帰で使用する加重リストオブジェクトを作成しました。この重みリストオブジェクトから、作成に使用したポリゴンのIDを取得したいと思います。 オブジェクトからこの情報を回復することは可能ですか?ここで加重リストオブジェクトから空間IDを抽出する、spdep R

再現可能な例である:これはうまくいくかもしれない

library(spdep) 
library(UScensus2000tract) 

# load data 
    data("oregon.tract") 

# get coordinates of centroids 
    coords <- coordinates(oregon.tract) 

# calculate a simple distance matrix between coordinates 
    d <- dist(coords) 
    d <- as.matrix(d) 

# Calculate Spatial weights Matrix (travel time) 
    my_weights <- mat2listw(d, row.names = row.names(oregon.tract)) 

# Now I'd like to extract from my_weights the polygon ids 
+1

: - '属性(my_weights)$ region.id' – ahly

+0

@ahly、それは完璧に動作します。私はそれを受け入れることができるように、答えとしてコメントを投稿してください。ありがとう。 –

答えて

1
library(spdep) 
library(UScensus2000tract) 

# load data 
    data("oregon.tract") 

# get coordinates of centroids 
    coords <- coordinates(oregon.tract) 

# calculate a simple distance matrix between coordinates 
    d <- dist(coords) 
    d <- as.matrix(d) 

# Calculate Spatial weights Matrix (travel time) 
    my_weights <- mat2listw(d, row.names = row.names(oregon.tract)) 

# Extract region ids from attributes of my_weights 
region.ids <- attributes(my_weights)$region.id 

head(region.ids) 
[1] "oregon_0" "oregon_1" "oregon_2" "oregon_3" "oregon_4" "oregon_5" 
関連する問題