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, 2022 in Machine Learning by Nandini
• 5,480 points
511 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, 2022 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, 2022 in Machine Learning by CoolCoder
• 4,420 points
673 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, 2022 in Machine Learning by Nandini
• 5,480 points
1,399 views
0 votes
0 answers

Create random numbers with left skewed probability distribution

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

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

Simple algorithm for generating random numbers with bigger/smaller probability

To move the density in one way, ...READ MORE

answered Apr 4, 2022 in Machine Learning by Nandini
• 5,480 points
2,212 views
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,370 points
5,108 views
0 votes
1 answer

Reasons for using the set.seed function

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

answered Jun 20, 2022 in Data Science by Sohail
• 3,040 points
403 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,570 points
1,030 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
1,180 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, 2022 in Machine Learning by Dev
• 6,000 points
543 views
0 votes
1 answer

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

captiongenerator.py is a Python script that generates ...READ MORE

answered Mar 17, 2022 in Machine Learning by Dev
• 6,000 points
516 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