[R-sig-Geo] knn2nb

Roger Bivand Roger.Bivand at nhh.no
Tue Aug 24 17:52:42 CEST 2010


On Tue, 24 Aug 2010, Sabira el Messlaki wrote:

> Dear list members,
>
> I want to plot a neighbours list of class nb. I thought that the plot 
> would show 8 neighbour lines. But this is not the case for my plot. Did 
> I do something wrong?
>
> col.knn2nb<-knn2nb(knearneigh(coords, k=8, longlat=F))
>
> plot(coords, border="grey")
> plot(col.knn2nb, coords, xlim=NULL, ylim=NULL, add=TRUE)

But:

table(card(col.knn2nb))
table(sapply(col.knn2nb, anyDuplicated))
table(sapply(1:length(col.knn2nb), function(i) i %in% col.knn2nb[i]))

show that each has eight unique neighbours, and that there are no 
self-neighbours. So perhaps neighbours in the same direction have lines 
that superimpose?

Roger

>
> Thanks in advance
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list