Skip to contents

Certifies that the values in the clu_num_points array, i.e. the number of points in each cluster, add up to num_points. If this is not the case, the clu_num_points array is modified in-place, incrementing the value corresponding to the smallest cluster while sum(clu_num_points) < num_points, or decrementing the value corresponding to the largest cluster while sum(clu_num_points) > num_points.

Usage

fix_num_points(clu_num_points, num_points)

Arguments

clu_num_points

Number of points in each cluster (vector of size \(c\)), where \(c\) is the number of clusters.

num_points

The expected total number of points.

Value

Number of points in each cluster, after being fixed by this function.

Details

This function is used internally by clusizes and might be useful for custom cluster sizing implementations given as the clusizes_fn parameter of the main clugen function.

Examples

clusters <- c(1, 6, 3)                   # 10 total points
clusters <- fix_num_points(clusters, 12) # But we want 12 total points
clusters                                 # Check that we now have 12 points
#> [1] 3 6 3