I'm looking for a way, preferably in R, to create a cluster of point data (specifically, the centroids of UK postcodes), where each cluster comes as close as possible to containing a certain number of people (between 100 and 200). The data I have is a SpatialPointsDataFrame of all postcodes with their Eastings/Northings, plus a column in the data for number of people in that postcode.
I can create a cluster of the point data using Kmeans, but that of course creates clusters with anywhere between 1 and several thousand people in them as it is doing so purely on the location of the point data.
Is there a way of clustering not just constraining on the number of clusters, but on the sum of people contained in the resulting cluster, as specified in my data?
My initial thought has been to do an initial set of clusters, and then recluster the clusters continually to create final clusters as close to the desired size as possible. However, at the moment I can only think of a way of doing that which basically involves a lot of trial and error. Is there an algorithm or some way of training R to try and achieve clusters of this specified size?