Compute k-means clusters for a SpatRaster. For large SpatRasters (with ncell(x) > maxcell) this is done in two steps. First a sample of the cells is used to compute the cluster centers. Then each cell is assigned to a cluster by computing the distance to these centers.
either the number of clusters, or a set of initial (distinct) cluster centres. If a number, a random set of (distinct) cells in x is chosen as the initial centres