Hi

I am trying to create a list of nearest neighbors using knearneigh and 
dinearneigh. To understand these I have been coding what these functions do:

For example, for dnearneigh, suppose I have x-y coordinates and the 
corresponding z values

# calculate distances between observations
data<-cbind(x,y,z)
coords<-cbind(x,y)
dis<-as.matrix(dist(coords,diag=T,upper=T))

# Create distance threshold =2
thrs<-2

nb<-list(vector("numeric",length(z)))

for (j in 1:nrow(data)){
    nb[[j]]<-as.vector(which(dis[j,]<=thrs))
}

nb

Then I can use this nb list to compute many local statistics.

For knearneigh, I can sort the distance matrix in ascending order and 
take the first n numbers as nearest neighbors. Then, how can I take a 
look at a list of neighbors when I use knearneigh?  unlist(nb,coords) 
just breaks the [[ ]] structure...

Thank for help in advance.

Taka

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to