R中是否存在期望值命令 [英] Does an expected value command exist in R
本文介绍了R中是否存在期望值命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我确定必须有一个直接的命令,但我已经搜索过,但找不到.如何从向量中获得期望值?
I'm sure there must be a straight forward command for this, but I've searched and can't find one. How do I get the expected value from a vector?
这里是值
y <- c(0.05, 0.01, -0.1)
以及它们的概率
p <- c(0.2, 0.7, 0.1)
我可以通过做得到E(Y)
sum(y*p)
但我认为可能有一个命令是对的,我就是找不到.谢谢!
But I think there is probably a command for it right, I just can't find it. Thanks!
推荐答案
您可以使用 weighted.mean
:
weighted.mean(y, p)
# [1] 0.007
这篇关于R中是否存在期望值命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文