Lets say I have a soccer team of 10 players (players) from which I should make two subteams of 5 players each and then compute the overall score for each team.
players <- read.table(text=
"paul 3
ringo 3
george 5
john 5
mick 1
ron 2
charlie 3
ozzy 5
keith 3
brian 3", as.is=TRUE)
I've already extracted a random set of 5 players:
t1 <- sample(players$V1, size = 5)
But one it comes to create the second team (excluding the players in the first one) and calculating the overall score for both teams I'm completed blocked.
You could try sampling the indices of players to construct the first team instead of sampling the names.
idx1 <- sample(1:nrow(players), 5)
You can actually use these indices to grab all the information about each team:
team1 <- players[idx1,]
team2 <- players[-idx1,]
The score for each team can be computed with sum(team1$V2)
and sum(team2$V2)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With