I am trying to find the the Centre of Gravity of the location using the two Lat-Longs, here I am trying to add the Quantity in Weights so that the output will be the weighted average. It is taking only the mean or simple average of the Lat-Longs in the output. Please help me to figure out the problem.
Input(Data.xlsx)
Customer Quantity Division Latitude Longitude
1234567 1234 A 22 73
7654321 234200 A 24 75
Cluster Output (1.csv)
Customer Quantity Division Latitude Longitude ClusterID
1234567 1234 A 22 73 1
7654321 234200 A 24 75 1
Output (2.csv)
ClusterID V1 V2
1 23 74
library(leaderCluster)
input_LatLong=readxl::read_excel("Data.xlsx")
input_matrix = as.matrix(input_LatLong[,4:5],ncol=2)
out_Cluster <- leaderCluster(input_matrix, radius = 600, weights = input_LatLong$Quantity, distance = "haversine", max_iter=10000)
output = data.frame(cbind(input_LatLong,out_Cluster$cluster_id))
colnames(output)[6]="ClusterID"
write.csv(output, file="C:/Users/Desktop/1.csv")
write.csv(out_Cluster$cluster_centroids,file="C:/Users/Desktop/2.csv")