Dan_yef Dan_yef - 1 month ago 7
R Question

Distribution of cards(simulation in r)

This is a vector of cards:

Cards
[1] 2 3 4 5 6 7 8 9 10 11 12 13 14 2 3 4 5 6 7 8 9 10 11 12 13 14 2 3 4 5 6 7 8 9
[35] 10 11 12 13 14 2 3 4 5 6 7 8 9 10 11 12 13 14


1:14 - cards values:

I want to distribute this cards among 2 players: 26 cards for both of them.

hand_1 <- sample(cards,size = length(cards)/2)


this is a hand for player 1.

How can I get the hand for player 2 correctly? I need somehow delete all elements from
cards
, that exist in
hand_1
. How can i do this without using loop technique.

Answer

You can simply:

matrix(sample(cards),ncol=2,dimnames=list(NULL,c("hands1","hands2")))

so you get a matrix whose columns are the two hands.

Comments