suit<-c("H","D","S","C") number<-c("A","K","Q","J",10:2) cards1<-suits1<-value1<-matrix(NA,4,13) for (i in 1:4) { for (j in 1:13) { cards1[i,j]<-paste(number[j],suit[i],sep="") suits1[i,j]<-suit[i] value1[i,j]<-number[j] } } cards<-as.vector(cards1) suits<-as.vector(suits1) values<-as.vector(value1) deck<-data.frame(cards,values,suits) draw<-sample(52,5,replace=FALSE) hand<-deck[draw,] hand num.sims<-10000 full.house<-NULL four.of.kind<-NULL exactly.one.pair<-NULL exactly.two.pairs<-NULL exactly.three.of.kind<-NULL zero.pairs<-NULL for (i in 1:num.sims) { draw<-sample(52,5,replace=FALSE) hand<-deck[draw,] unique.vals<-unique(hand$values) full.house[i]<-ifelse(length(unique.vals)!=2,0, ifelse(sum(hand$values==unique.vals[1])==2 | sum(hand$values==unique.vals[1])==3, 1, 0)) four.of.kind[i]<-ifelse(length(unique.vals)!=2,0, ifelse(sum(hand$values==unique.vals[1])==1 | sum(hand$values==unique.vals[1])==4, 1, 0)) exactly.one.pair[i]<-ifelse(length(unique.vals)==4,1,0) exactly.two.pairs[i]<-ifelse(length(unique.vals)==3 & max(table(hand$values))==2,1,0) exactly.three.of.kind[i]<-ifelse(length(unique.vals)==3 & max(table(hand$values))==3,1,0) zero.pairs[i]<-ifelse(length(unique.vals)==5,1,0) } mean(full.house) 13*12*choose(4,3)*choose(4,2)/choose(52,5) # truth mean(four.of.kind) 624/2598960 # truth mean(exactly.one.pair) 13*choose(4,2)*choose(12,3)*4^3/choose(52,5) # truth mean(exactly.two.pairs) (13*12*choose(4,2)*choose(4,2)*11*4/2)/choose(52,5) # truth mean(exactly.three.of.kind) 13*4*choose(12,2)*4^2/choose(52,5) #truth mean(zero.pairs) (52*48*44*40*36/factorial(5))/choose(52,5)