选择特定数字的可能性 [英] Choose specific number with probability
本文介绍了选择特定数字的可能性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何选择具有特定概率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 ofx
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屋!
查看全文