Skip to content
Prev 11277 / 29559 Next

spdep: show neighbors from "dnearneigh"

Thanks Roger and Mathieu.  Instead of:
 [[1]]
  [1]   2  10  11  15  17

I now have:
1	2
1	10
1	11
1	15
1	17

For the last piece of this analysis, I would like to generate a list of
neighbor distances to complete my table.
nbd <- nbdist(nb, SpatialPoints)
nbd
[[1]]
 [1] 84.95881 90.35486 75.92760 22.20360 81.00617

But ideally, I would like to have
1	2	84.95881
1	10	90.35486
1	11	75.92760
1	15	22.20360
1	17	81.00617

I can't use nb2listw (and then merge), because this is an object of class
"nbdist".  I also cannot use the Mathieu's melt method, because I nb2mat
also requires an object of class "nb".

Suggestions?




-----Original Message-----
From: Roger Bivand [mailto:Roger.Bivand at nhh.no] 
Sent: Tuesday, March 22, 2011 1:30 AM
To: Mathieu Rajerison
Cc: kmringelman at ucdavis.edu; r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] spdep: show neighbors from "dnearneigh"
On Tue, 22 Mar 2011, Mathieu Rajerison wrote:

            
use
No, the question was how to convert to a two-column from-to 
representation, and a direct route is:

example(read.gal)
# to get an nb object
us48.q
us48.q[1:2]
res <- listw2sn(nb2listw(us48.q))[,1:2]
res[1:9,]
str(res)

If you need a matrix, do as.matrix(res).

Roger
the
have
an
make
want,