Anna R.

asked • 02/10/21

Modify the function poker() from Ch. 12 of the Primer to a function called bridge() which deals 13 cards instead of 5. The function should also count the hand’s points as follows.

poker = function() {

# a function to deal a poker hand

# first, create a card deck

suit = rep(c("S","H","D","C"),13)

suit = sort(suit)

suit = as.factor(suit)

denom = c("A",as.character(2:10),"J","Q","K")

denom = rep(denom,4)

denom = as.factor(denom)

carddeck = data.frame(denom,suit) # a 52x2 frame

#

# shuffle and deal five (randomly select 5 from the deck)

cardnums = sample(52,5)

mycards = carddeck[cardnums,]

mycards

}

a.   Highcard.points: score 4 points for each Ace in the hand, 3 points for each King, 2 points for each Queen, and 1 point for each Jack (add these together).  Hint: table(myhand[,”denom”])

b.     Distribution.points: score 3 points for each suit that has no cards in the hand (a “void”), 2 points for each suit that has only 1 card (a “singleton”), and 1 point for each suit that has only two cards (a “doubleton”). Hint: table(myhand[,”suit”])

The function should return a list including the hand itself (a 13 by 2 data frame), the value of Highcard.points, and the value of Distribution.points. After you’ve created the function and checked it, provide me with a printout of the function and at least one example of its output list.

1 Expert Answer

By:

David B. answered • 05/22/21

Tutor
5.0 (257)

Math and Statistics need not be scary

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.