Probabilities in R programming

0 votes

I'm solving a probability problem. The question is to calculate the probability of drawing two face cards (Jack, Queen, King) in a row. Simulate a standard deck of 52 cards (no Jokers). Sample two cards from the deck 1000 times (remember, we do not replace the card after drawing). How does the proportion of times two face cards were drawn compare to the probability you calculated? 

I tried this:

 poker <- c(1:10, "J", "Q", "K")

 poker_face <- sample(poker, size = 1000, replace = FALSE)

I'm getting the following error:

 Error in sample.int(length(x), size, replace, prob) :    cannot take a
 sample larger than the population when 'replace = FALSE'
May 27, 2019 in Data Analytics by Sophie may
• 10,610 points
1,376 views

1 answer to this question.

0 votes

This should work:

poker_face <- replicate(1000, sample(poker, size =2, replace = FALSE))
answered May 27, 2019 by Zulaikha
• 910 points

Related Questions In Data Analytics

0 votes
2 answers

What are the rules to define a variable name in R programming language?

The same rules almost follow for all ...READ MORE

answered Aug 26, 2019 in Data Analytics by anonymous
• 33,030 points
14,425 views
+1 vote
1 answer

Difference between factor and as.factor in R programming

Hey @Ali, as.factor is a wrapper for ...READ MORE

answered Oct 29, 2018 in Data Analytics by Maverick
• 10,840 points
4,490 views
0 votes
1 answer

What is active binding in R programming

Active bindings in R are much like ...READ MORE

answered Oct 30, 2018 in Data Analytics by Maverick
• 10,840 points
1,079 views
+1 vote
1 answer

Remove NA values from the output in R programming

Edit your code: columnmean <- function(x, removeNA = ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 52,360 points
640 views
+10 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 9, 2018 in Data Analytics by Abhi
• 3,720 points
1,119 views
+1 vote
1 answer

Error saying "vector size cannot be NA" when using R with data mining

You can use the removesparseterm function.  Removes sparse ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,840 points
4,366 views
+1 vote
2 answers
0 votes
1 answer

Trying to find frequent itemsets of a data set using arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", "milk", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,840 points
549 views
0 votes
1 answer

Changing variable values using R programming

This should work: df$symbol <- as.character(df$symbol) df$symbol[df$symbol == "ABCD.BO"] ...READ MORE

answered May 27, 2019 in Data Analytics by Zulaikha
• 910 points
696 views
0 votes
1 answer

R programming error: Plot error - “Col=”red“

Fix this line: polygon(c(0,0,1),c(1,2,1), col="red", density=c(30, ...READ MORE

answered May 28, 2019 in Data Analytics by Zulaikha
• 910 points
617 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP