选择特定数字的可能性 [英] Choose specific number with probability

查看:77
本文介绍了选择特定数字的可能性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何选择具有特定概率p的数字?

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

假设我们必须在{0, 1}和概率p代表选择1之间进行选择.

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

因此,当p=0.8时,我们选择80%的1和20%的0.

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

R中有一个简单的解决方案吗?

Is there a simple solution in R for this?

推荐答案

看看从帮助文件中,您可以阅读:

From the helpfile you can read:

sample使用或不使用替换从x的元素中获取指定大小的样本.

sample takes a sample of the specified size from the elements of x using either with or without replacement.

sample中的参数prob充当...

and the argument prob in sample acts as ...

一个概率权重向量,用于获取要采样的向量的元素.

A vector of probability weights for obtaining the elements of the vector being sampled.

这篇关于选择特定数字的可能性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆