Random generate a series of Poisson distribution numbers
1
1
Entering edit mode
5.1 years ago
whaiyu06 ▴ 80

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 • 821 views
ADD COMMENT
2
Entering edit mode
5.1 years ago
whaiyu06 ▴ 80

We can use map apply:

mapply(x, FUN = rpois, lambda = y)
ADD COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 2711 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6