# Approach to Problem- K-Means with distribution constraint

I have 4 variables A (continuous), B (continuous), C (categorical-binary), and D (categorical-multinomial) which I need to split into K (known) groups. However, in addition to minimizing the distance between observations based on A and B, the groups need to be as evenly distributed possible by C and D.

I am not sure how to approach this problem- is there a way that I can use a modified version of the K-means algorithm to achieve my desired result?

You can achieve this in R by using the kkmeans function of the kernlab package and specify a kernel function that is suitable for your purpose and minimizes the distance between A and B and maximizes the distance between C and D.