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.