In K-means clustering, what is the method for comparing different choices of k in terms of overall average within-cluster distance? What is the R function you can use for it? Please also describe that method briefly.

In K-means clustering, what is the method for comparing different choices of k in terms of overall average within-cluster distance? What is the R function you can use for it? Please also describe that method briefly.