What's the difference between the 2 codes?
> set.seed(23)
> x <- sample(1:1000,1000)
> for (i in 1:1000){
+ x[i] <- mean(rpois(40,5))
+ }
> mean(x)
[1] 5.007775
> var(x)
[1] 0.1342569
> set.seed(23)
> x <- rep(0,times=1000)
> for (i in 1:1000){
+ x[i] <- mean(rpois(40,5))
+ }
> mean(x)
[1] 5.01135
> var(x)
[1] 0.1250763
How is sample being different from rep here? I have even checked rep==Sample and it's TRUE. This doesn't make sense at all.