簡體   English   中英

卡的分配(R中的模擬)

[英]Distribution of cards(simulation in r)

這是紙牌的向量:

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-卡值:

我想在2位玩家之間分配這張卡:兩個人都有26張卡。

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

這是玩家1的牌。

如何正確獲得玩家2的手牌? 我需要從cards刪除hand_1中存在的所有元素。 我如何不使用循環技術就能做到這一點。

您可以簡單地:

matrix(sample(cards),ncol=2,dimnames=list(NULL,c("hand1","hand2")))

這樣就得到一個matrix其列為兩只手。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM