Nithisha Khasnavis - 3 years ago 126

R Question

I entered the following command in R:

`my_pois <- replicate(100,rpois(5,10))`

I believe this creates 100 sets of 5 numbers in which each set should have a mean of 10. However when I look at the mean of each column(set created), this is what I get:

`[1] 10.8 9.4 9.0 11.2 11.6 11.6 7.8 12.4 9.6 11.0 9.6 9.8 10.0 8.6 9.8 8.6 9.4`

[18] 11.4 12.0 8.4 10.2 10.2 10.8 10.2 7.6 9.8 8.4 10.6 11.6 8.6 9.6 11.0 11.0 10.0

[35] 9.8 9.2 8.2 8.2 10.2 9.0 10.4 9.2 10.4 10.0 11.8 13.8 10.2 9.8 12.4 10.4 9.8

[52] 9.8 8.6 7.4 9.2 9.0 7.4 9.2 9.4 11.8 9.2 9.8 11.6 9.8 10.8 8.6 12.4 10.4

[69] 9.4 9.4 9.0 11.2 10.6 9.4 9.6 8.2 9.6 10.6 10.6 8.2 9.2 10.0 11.2 9.0 9.6

[86] 10.4 8.0 10.2 9.8 7.4 9.6 9.0 7.2 8.4 11.8 10.8 9.4 12.4 11.2 12.0

Shouldn't they all be 10 since we specified a mean of 10?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You can calculate the mean of all the samples using the following.

```
k <- apply(my_pois,2, function(x) mean(x))
```

You are creating a random sample which should be ** approximately** equal to 10. Since your sample is small it is unlikely to equal 10 exactly. As your sample size grows the mean comes closer to 10.

Here is one source I would review

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**