Novice R programmer struggling to add a spatial component to large data set (>1500 obs)
Given a list of: observations, corresponding x/y points (not lat/long), and attributes; how can I write an algorithm to return the sum of variable "Z" for all observations within a given radius (10) of the observation in question. I need to do this for each observation.
Simplified data headers read as follows:
OBS X Y Z**
A 56.55 -289.65
B 52.59 -287.82
C 58.34 -284.58
Any assistance would be appreciated. Thanks.
The key is to use
mapply()to apply a function to multiple vectors at a time - here: the X and Y components of yourdata.frame. Which function? One that adds theZvariable for all observations in yourdata.framethat are at mostradiusaway from the "anchor point" (which we run over all entries).Note that of course each point's
Zitself is counted in its radius. If you don't want that, you'll need to subtractfoo$Z.Look at
?mapply.