0

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")
Shunty
  • 3
  • 3
  • @GregorThomas, I tried to add the input data and output, it is not coming in format. – Shunty May 10 '22 at 15:59
  • If your data is a data frame, then the `dput` result should start with `structure(list(` and go from there. Pick a suitable sample of data to share. If your data is just 2 rows and 5 columns as in your picture then `dput(input_LatLong)` should be fine. If you data is bigger, pick out some relevant rows and columns, eg., `dput(input_LatLong[1:3, 1:5])` for the first 3 rows and first 5 columns. If it's still giving you trouble, have a look at the [FAQ on making reproducible examples in R](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Gregor Thomas May 10 '22 at 16:08
  • @GregorThomas, Thanks for trying to help. But I did not quite get it into the right format. I just pasted the data line by line. – Shunty May 10 '22 at 16:27

0 Answers0