Choose specific number with probability

0 votes
How can one choose a number with a specific probability p?

Say we must choose between {0, 1} and the probability p stands for choosing 1.

So when p=0.8 we choose 1 with 80% and 0 with 20%.

Is there a simple solution in R for this?
Mar 7 in Machine Learning by Nandini
• 5,480 points
26 views

1 answer to this question.

0 votes

Examine the sample function.

set.seed(1)
sample(c(0,1), size=12, replace=TRUE, prob=c(0.2,0.8))

1 1 1 0 1 0 0 1 1 1 1 1 

 sample takes a sample of the specified size from the components of x and in sample, 
and the argument prob in sample is a vector of probability weights for obtaining the elements of the sampled vector.

answered Mar 14 by Dev
• 6,000 points

Related Questions In Machine Learning

0 votes
1 answer

Getting one word as caption with zero probability using pretrained checkpoints for image captioning-im2txt

Under caption_generator.py change the following line as follow ...READ MORE

answered Feb 27 in Machine Learning by CoolCoder
• 4,360 points
31 views
0 votes
1 answer

Random numbers with user-defined continuous probability distribution

You can use the rejection sampling approach ...READ MORE

answered Mar 25 in Machine Learning by Nandini
• 5,480 points
31 views
0 votes
0 answers

Create random numbers with left skewed probability distribution

I would like to pick a number ...READ MORE

Mar 25 in Machine Learning by Dev
• 6,000 points
60 views
0 votes
1 answer
0 votes
1 answer

How to sample n random rows per group in a dataframe?

You can assign a random ID to ...READ MORE

answered Jul 3, 2018 in Data Analytics by Sahiti
• 6,380 points
3,740 views
0 votes
1 answer

Reasons for using the set.seed function

The requirement is a desire for repeatable ...READ MORE

answered Jun 20 in Data Science by Sohail
• 2,960 points
16 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,610 points
424 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
468 views
0 votes
1 answer

Empirical probability in R with x1+x2>2*x3

It's easy to duplicate random draws with ...READ MORE

answered Mar 15 in Machine Learning by Dev
• 6,000 points
39 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP