[R-sig-eco] nearest neighbours - amended
Anna Marburg
MarburgA at landcareresearch.co.nz
Mon Sep 28 00:07:12 CEST 2009
Hello again Katia -
Of course, before you can use the functions in spdep, you will need to
load it, like this:
library(spatstat)
library(spdep)
data(amacrine)
ama.split <- split(amacrine) # make one .ppp for each mark
summary(ama.split)
coords <- cbind(ama.split[["on"]]$x, ama.split[["on"]]$y)
class(coords)
rn <- 1:nrow(coords) # if your points have meaningful ids put them here
# find 4 nearest neighbors:
k4 <- knn2nb(knearneigh(coords, k = 4), row.names = rn)
# calculate distances from each point to its neighbors
dsts <- nbdists(k4, coords)
summary(unlist(dsts))
# find all neighbors closer than some threshold
close.nb <- dnearneigh(coords, 0, 0.12330, row.names=rn)
# what do these different neighborhood objects look like?
summary(k4, coords)
summary(close.nb, coords)
# test the effect of different set logic
summary(intersect.nb(k4, close.nb), coords)
summary(union.nb(k4, close.nb), coords)
Sorry for the error,
Anna
Dr. Anna E. Marburg
Ecosystem Processes Team
Landcare Research
P O Box 40
Lincoln 7640
NEW ZEALAND
phone + 64 3 321 9729
MarbugA at landcareresearch.co.nz
>
> Message: 1
> Date: Fri, 25 Sep 2009 11:31:08 -0400
> From: K?tia Emidio <kat.emidio at gmail.com>
> Subject: [R-sig-eco] nearest neighbours
> To: r-sig-ecology at r-project.org
> Message-ID:
> <cf3004ea0909250831n38dfd0bbl853e43d4b382da8d at mail.gmail.com>
> Content-Type: text/plain
>
> Hi, What function should I use to find out who are my 5 nearest
> neigbours(N)
> or in a specified radius, in a .ppp (object) where the marks are
> factors?
> thanks
> Katia
>
> --
> K?tia Em?dio da Silva MSc
> Eng. Florestal
> Pesquisador
> Embrapa Amaz?nia Ocidental
>
> [[alternative HTML version deleted]]
>
>
More information about the R-sig-ecology
mailing list