My goal
My goal is to find, based on the index, the best combinations of 10 players that have a score sum between 95.5-100.4.
The detail
There is an important detail. From the 10 players, there should be based on the role column 2C (two Centers), 4F (four Forwards), 4*G (four Guards).
Atm I am struggling with for loops, but I am sure there is something bright in the dplyr package that I am missing. Any help or guidance is highly appreciated.
set.seed(123)
players <- paste("player",rep(1:20))
score <- runif(20, min=4, max=16.7)
index <- runif(20, min=-1, max=9)
role <- rep(c("C","F","F","G","G"),4)
df <- data.frame(players, score, index,role)
df
#> players score index role
#> 1 player 1 7.652235 7.8953932 C
#> 2 player 2 14.011475 5.9280341 F
#> 3 player 3 9.194007 5.4050681 F
#> 4 player 4 15.214321 8.9426978 G
#> 5 player 5 15.943935 5.5570580 G
#> 6 player 6 4.578568 6.0853047 C
#> 7 player 7 10.706940 4.4406602 F
#> 8 player 8 15.333722 4.9414202 F
#> 9 player 9 11.003225 1.8915974 G
#> 10 player 10 9.799007 0.4711365 G
#> 11 player 11 16.151783 8.6302423 C
#> 12 player 12 9.757344 8.0229905 F
#> 13 player 13 12.605147 5.9070528 F
#> 14 player 14 11.272444 6.9546742 G
#> 15 player 15 5.307143 -0.7538632 G
#> 16 player 16 15.427777 3.7779597 C
#> 17 player 17 7.125314 6.5845954 F
#> 18 player 18 4.534156 1.1640794 F
#> 19 player 19 8.164593 2.1818101 G
#> 20 player 20 16.122196 1.3162579 G
Created on 2021-10-16 by the reprex package (v2.0.1)
Thank you for your time