## Create the deck of 52 cards ## Each row of the deck matrix is one card in the deck deck <- array(0, c(52,2) ) ## The first column of the deck matrix is the cards number deck[,1]=c("Ace",2,3,4,5,6,7,8,9,10, "Jack", "Queen","King") ## The second column of the deck matrix is the cards suit deck[,2]=c("Clubs", "Diamonds", "Hearts", "Spades") ## We now have our deck as a matrix ## So the third card in our deck is ## deck[3,], etc. ## Compute the prob of drawing an Ace off ## the top of the deck reps <- 1e6 gotIt <- 0 for (r in 1:reps ) { ## shuffle the deck deck <- deck[sample(52),] ## Add one to our counter if we draw an ## Ace off of the top of the deck gotIt <- gotIt+1*(deck[1,1] == "Ace" ) } prb <- gotIt/reps print(prb)