问题 I have a large data frame with more than 100 000 records where the values are sorted For example, consider the following dummy data set df <- data.frame(values = c(1,1,2,2,3,4,5,6,6,7)) I want to create 3 groups of above values (in sequence only) such that the sum of each group is more or less the same So for the above group, if I decide to divide the sorted df in 3 groups as follows, their sums will be 1. 1 + 1 + 2 +2 + 3 + 4 = 13 2. 5 + 6 = 11 3. 6 + 7 = 13 How can create this optimization