A pretty complicated sample i would appreciate some help with!

Hello people.
In class we encountered a pretty complexed sampling problem. well, for me its complex.
It goes like this:
Create a vector of 5 names
Create a vector of all 52 cards (no jokers)
Hand your players 5 cards.
Well, that basically it.
I tried to start by creating my vector of names c("ä", "b", "c", "d", "e")
then the stack of cards i was like.. neh. its basically 52 unique items, so a c(1:52) will do just fine for the sake of programming.
Now im stuck.
Obviously we're talking about a replace=F argument, but the output has to be each name along with 5 cards. im pretty stuck.

Ill appreciate all help

Something like this? I made a list to hold the players hands, you can use their names for indexing.
Every time you deal you have to remove the cards from the deck, as well as add them to the players hands.


cards <- 1:52

players <- letters[1:5]

hands <- vector("list", length(players))
names(hands) <- players

for (i in players){

  deal <- sample(cards, 5)
  cards <- setdiff(cards, deal)
  hands[[i]] <- deal


#> $a
#> [1]  4 39  1 34 23
#> $b
#> [1] 48 16 20 37 24
#> $c
#> [1] 27 12  9 11 18
#> $d
#> [1] 32 38 49 51 25
#> $e
#> [1]  2 33  5  8 15

Created on 2021-03-08 by the reprex package (v1.0.0)

1 Like

That looks pretty damn awesome man! Plus, how could I forget the letters commands. Jesus.
Thank you very much

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.