This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Random generate a series of Poisson distribution numbers

Dear all,

I want to generate a series of random number for the Poisson distribution as below: produce 2 random Possion distribution numbers with the mean is 1; 3 random Possion distribution numbers with the mean is 6; 2 random Possion distribution numbers with the mean is 4; 4 random Possion distribution numbers with the mean is 3 at the same time using R without forloop i.e.

sapply(x,rpois,lambda = y)

but both x and y are vectors ,and I should get a list like

[[1]] rpois(x[1],lambda=y[1])  [[2]] rpois(x[2],lambda=y[2]) .....[[i]] rpois(x[i],lambda=y[i])

Thanks

r

1 answer

We can use map apply:

mapply(x, FUN = rpois, lambda = y)

I moved this from comment to answer since it is the answer to the question.

Log in to answer this question.