Creating groups of equal sum in R
问题 I am trying to group a column of my data.frame/data.table into three groups, all with equal sums. The data is first ordered from smallest to largest, such that group one would be made up of a large number of rows with small values, and group three would have a small number of rows with large values. This is accomplished in spirit with: test <- data.frame(x = as.numeric(1:100000)) store <- 0 total <- sum(test$x) for(i in 1:100000){ store <- store + test$x[i] if(store < total/3){ test$y[i] <- 1