In this study, we study the core concepts of the K-Means algorithm, explore its algorithmic framework, computation steps, and practical applications. Using data that is used as a basic need to perform calculations from the k-means algorithm optimization method. Using data taken from the r studio dataset with the EuStockMarkets dataset. The purpose of this study is to optimize the k-means algorithm and cluster the clustering process from a dataset, minimizing the objective function that has been set in the clustering process. The tools used are R Studio. Based on the results of this study, profiling of each group formed can be carried out. Based on the grouping results that have been carried out, the grouping results are 75.7% the accuracy of the statistical Gap method in optimizing clusters from existing datasets and the results of 92.9% are obtained from the results of minimizing the object functions in the dataset from grouping with k-means. The smaller the percentage in this grouping process the better it is in optimizing the clusters from the dataset. The author applies the k-means clustering algorithm to minimize objects for grouping from the EuStockMarkets dataset which consists of 4 variables. And the author uses the Statistical Gap method to optimize the clusters from the dataset.