Skip to content

Help with Centroids

1 message · Robert David Burbidge

#
# construct the dataframe
`TK-QUADRANT` <- c(9161,9162,9163,9164,10152,10154,10161,10163)
LAT <- 
c(55.07496,55.07496,55.02495,55.02496,54.97496,54.92495,54.97496,54.92496)
LON <- 
c(8.37477,8.458109,8.37477,8.45811,8.291435,8.291437,8.374774,8.374774)
df <- data.frame(`TK-QUADRANT`=`TK-QUADRANT`,LAT=LAT,LON=LON)

# group the data and calculate means by group
df$group <- floor(df$TK.QUADRANT/10)*10
out <- aggregate(df[c('LAT','LON')],by=list(df$group),mean)
print(out)

# see also:
# 
https://livefreeordichotomize.com/2018/06/27/bringing-the-family-together-finding-the-center-of-geographic-points-in-r/

Rgds,
Robert
On 14/11/2018 11:13, sasa kosanic wrote: