A continuation from this SO question
I have a very large df
and want to sum column value
for each lat
/long
that is within the radius.
set.seed(1)
radius<-10000 # In meters
lat<-runif(10,-90,90)
long<-runif(10,-180,180)
value<- runif(10,200,7000)
id<-1:10
dat<-cbind(id,lat,long, value)
Is there a RAM efficient way of doing this?
The original post suggested the following to count occurrences within the radius, I'm wondering whether I can sum a column in a similar way?
library(geosphere)
cbind(dat, X=rowSums(distm (dat[,3:2],
fun = distHaversine) / 1000 <= 10000)) # number of points within distance 10000 km