首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从权重列表对象spdep R中提取空间ids

从权重列表对象spdep R中提取空间ids
EN

Stack Overflow用户
提问于 2017-05-03 22:41:58
回答 1查看 335关注 0票数 0

我使用mat2listw{spdep}创建了一个权重列表对象,稍后我将在空间回归中使用该对象。我想从这个权重列表对象中检索用于创建它的多边形的it。是否有可能从对象中恢复此信息?

下面是一个可重复的例子:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-04 22:12:34

代码语言:javascript
复制
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"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43771149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档