Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. A standard deck of playing cards can be created in R as a data frame with the following commands. suits

3. A standard deck of playing cards can be created in R as a data frame with the following commands.

suits <- c("D","C","H","S") # D =  Diamond, C =  Club, H =  Heart, S =  Spade ranks <- 2:14 # 11 = Jack, 12 = Queen, 13 = King, 14 = Ace deck <- matrix(, nrow = 52, ncol = 2) colnames(deck) = c("suit", "rank") deck <- as.data.frame(deck) deck$suit <- rep(suits, 13) deck$rank <- rep(ranks, 4) 

(a) Describe the structure of the data framedeck, what are the information contained in its row and column?

(b) A poker hand is a set of five playing cards. Sample a poker hand using the data framedeckand name it ashand.

(c) A flush is a hand that contains five cards all of the same suit. a logical value namedis.flushwhich isTUREif and only ifhandis a flush.

Hint: You may usehand <- deck[c(17,9,1,49,41),]as a test case. Theunique()function would be useful.

(d) A straight is a hand that contains five cards of sequential rank. Note that both AKQJ10 and 5 4 3 2 A are considered to be straight, but Q K A 2 3 is

not.a logical value namedis.straightwhich isTUREif and only ifhandis a straight. Use a test case similar to that in (c) to verify your answer.

Hint: Theall()function would be useful.

(e) A straight flush is a hand that is both a straight and a flush. a logical value namedis.straightflushwhich isTUREif and only ifhandis a straight flush. Modify the logical valuesis.flushandis.straightin (c) and (d) such that they becomesFALSEifhandis a straight flush. Use a test case similar to that in (c) to verify your answer.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pell And Pell–Lucas Numbers With Applications

Authors: Thomas Koshy

1st Edition

1461484898, 9781461484899

More Books

Students also viewed these Mathematics questions