Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

quiz.deck52 We will use R to build a dataset representing a standard deck of 52 playing cards. Your dataset should have 52 wws and one

quiz.deck52

We will use R to build a dataset representing a standard deck of 52 playing cards. Your dataset should have 52 wws and one column for each characteristic of a playing card. These characteristics include:

color E {"black", "red"}

suit E {"clubs", "spades" , "diamonds" , "hearts"}

name E {"ace", "2" , 11311 , , "10" , "jack" , "queen" , "king"}

rank E {1,2, 3, ...' 12, 13}

value E {1,2, 3, . . . , 9, 10 , 10 , 10 , 10 }

1. (50pts) Build a column vector for each characteristic. Use commands like c () , rep() , paste () . Use the length () command to verify that each vector has 52 elements.

As an example, let's build the color vector first. First, study the rep() function in R.

h e lp ( r ep )

Read the help page . It helps to scroll dovvn to Examples and paste that code into R to see how things work. The main thing for this quiz is to know when to use the each argument . Running the commands below might help:

r ep ( c ( " b l ack " , " r ed " ) , t im e s = 26 )

r ep ( c ( " b 1a ck " , " r ed " ) , 26 ) # same result :

# since 26 is the second argument ,

R int erpret s it as times

r ep ( c ( " b l ack " , " r ed " ) , e ach = 26 )

# not e the diff erenc e

Either way is ok, but your choice affects huw you build the other vectors. We used

each=26 in class, so I'm going with that for now:

c o l or <- r ep ( c ( " b l ack " , " r ed " ) ,

e ach = 26 ) c o l or

# look at your v ector

l engt h ( c o l or ) #make sure it has the rig ht length

Done with color. Nuw do the others.

2. (l0pts) Use data. f rame () to combine the columns into a data.frame called mydeck1 .

Put the columns in an order that makes sense.

m yd e c k 1 <- d at a . f r ame ( YOU R C OLUM NS GO HERE , SEPAR ATED BY C OMM AS )

3. (l0pts) Use dim() to confirm that mydeck1 has 52 rows and 5 columns.

4. (l0pts) Use names (mydeck) to display the column names. Run names (mydeck ) <

toupper (names (mydeck) ) to convert the column names to upper case.

5. (l0pts) Build the same deck again using a single call to data.f rame() . Name this new object mydeck2 and specify the same upper case column names as in part 1 above. Make the column order the same as in mydeck1 . Your code will look something like this:

m yd e c k 2 <- d at a . f r am e ( C OLOR = . . . , SU IT = . . . , et c .)

where the ... are copies of the vector-building commands from part 1. It 's a single line of code, but you can use returns to break it up.

6. (l0pts) Check whether mydeck1 and mydeck2 are the same. Do it three ways :

Use your eyeballs. Do they look the same?

Use the Boolean operator "=='':

m yd e ck 1 == m yd e ck 2

How does this relate to your eyeball check?

Use the ident ical () function:

id en t i c al ( m yd e ck 1 , m yd e ck 2 )

How is this result different from the previous two?

7. (20pts extra credit) Repeat part 1, but start with this command :

c o l or <- r ep ( c ( " b l ack " , " r ed " ) , 26 )

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_2

Step: 3

blur-text-image_3

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

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions