I have a function distance(lat1,lon1, lat2,lon2) that calculates the distance of 2 points.
Suppose I have a dataframe with some points and values:
n<-c(lon = -1.729219, lat = 29.730836)
o<-c(lon = -5.041928, lat = 28.453022)
e<-c(lon = -2.700067, lat = 29.198922)
s<-c(lon = -5.212864, lat = 28.531739)
centro<-matrix(c(n,o,e,s), ncol=2, byrow=TRUE)
d<-data.frame(c=centro, amount=c(3.5,3.5,3.5,3.5), count=c(12,12,12,12))
colnames(d)<-c('lon','lat','amount','count')
I want to get a a new frameset with the values aggregated to the closest one of them (I don't care wich)
Suppose I have a rad of 10km and n and o are at a distance of 7 and e and s are at distance 20 from any other point I would expect a new data frame with 3 values: e, s and a new value with amount and count the sum of the other 2 and lat and long either the ones from n or the ones from o.
I suppose there's a simple way to do this in R but I couldn't find it.
Thanks