在 R 中找到 n 个泊松值的期望

Finding the expectation of n Poisson values in R

我写了下面的代码:

n <- 5
lambda <- 2
randomNumbers <- rpois(n, lambda)
prob <- dpois(randomNumbers, lambda)

到目前为止我的代码是否正确?

如何找到 5 个泊松值的期望值?

eX <- mean(randomNumbers)

或者,

weighted.mean(randomNumbers, prob)
n <- 5
lambda <- 2
randomNumbers <- rpois(n, lambda)
# estimate of P(X = 0), for example
mean(randomNumbers == 0)
# estimate of E[X]
mean(randomNumbers)