[英]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: 1:14-卡值:
I want to distribute this cards among 2 players: 26 cards for both of them. 我想在2位玩家之间分配这张卡:两个人都有26张卡。
hand_1 <- sample(cards,size = length(cards)/2)
this is a hand for player 1. 这是玩家1的牌。
How can I get the hand for player 2 correctly? 如何正确获得玩家2的手牌? I need somehow delete all elements from cards
, that exist in hand_1
. 我需要从cards
删除hand_1
中存在的所有元素。 How can i do this without using loop technique. 我如何不使用循环技术就能做到这一点。
You can simply: 您可以简单地:
matrix(sample(cards),ncol=2,dimnames=list(NULL,c("hand1","hand2")))
so you get a matrix
whose columns are the two hands. 这样就得到一个matrix
其列为两只手。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.