[R-sig-Geo] Defining neighbors base on same location

Tom Gottfried tom.gottfried at tum.de
Thu Mar 29 07:35:21 CEST 2012


Hi,

Am 29.03.2012 01:08, schrieb Roosbeh Nowrouzian:
> Hi list members:
>
> Is there any way to define neighbors in R as any other observation
> with distance to the corresponding point equal to 0.
>
> I am trying to define neighbors base on the same location ( the same
> Household members are linked to each other). I tried defining
>
> weights base on  fixed distance bounds:
> neighbordistance.nb<- dnearneigh ( coords, d1=0, d2=0.00001, row.names=IDs
> )
> But this function does not define other Household members (distance=0) as
> the neighbor.
>
> When trying fixed number of neighbors:
> neighbor3.knn<- knearneigh ( x=coords , k=3, longlat= FALSE, RANN=TRUE )
> This function defines other Household members(distance =0) as neighbor but
> the problem with this function is that each Household has different
> Household number so different number of neighbors is required for each
> Household.

neighbor3.knn <-
    mapply(function(n, coord) knearneigh(x=coord,
                                         k=n, longlat=FALSE,RANN=TRUE),
           ns, lapply(1:nrow(coords), function(i) coords[i,]))

Assuming you have a vector 'ns' with the number of household members per 
household, this should give you a list with each element defining the 
neighbours you desire. I hope I didn't misunderstand your question.

HTH,
Tom

> It would be kind of you letting me know if there is a way to define
> neighbors base on  zero distance with the corresponding point.
> Appreciate it.
>
> Roosbeh Nowrouzian
> PhD student
> Department of Civil Engineering
> University of Florida
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Technische Universität München
Department für Pflanzenwissenschaften
Lehrstuhl für Grünlandlehre
Alte Akademie 12
85350 Freising / Germany
Phone: ++49 (0)8161 715324
Fax:   ++49 (0)8161 713243
email: tom.gottfried at wzw.tum.de
http://www.wzw.tum.de/gruenland



More information about the R-sig-Geo mailing list