[R-sig-Geo] sum number of events by covariate using applynbd

Wall, Wade A ERDC-RDE-CERL-IL Wade.A.Wall at usace.army.mil
Fri May 11 23:23:14 CEST 2012


Hi all,

I am wanting to sum the number of events within r=5 distance of a set of points and segregate by a covariate. I want to use the function applynbd, but not sure how to write a custom function to do this.

For example, I have a ppp object, LS.ppp. LS.ppp$marks has two levels, M and F. 

For each point in the data set, I want to assess the sum of all points within r=5 that are M and the sum of all points that are female. 

The results would be a dataframe  of N rows, with N = the number of points in the ppp object. 

The two columns would be number of females, and number of males.

I think this could be done using dist() and looping over it for each row and then matching with a dataframe, but that seems to be a clunky way of doing it.

Does anyone know how to do this? I see how to use applynbd to get the sum of the points, but not the sum by covariate.

Thanks for any information,

Wade A. Wall



More information about the R-sig-Geo mailing list