# Statistical Analysis: an Introduction using R/R/Random sampling

From Wikibooks, open books for an open world

#### Random sampling[edit]

From the help page, we have seen that the sample function can take a number of different arguments.
As noted, our "fair die" model is one of sampling with replacement: the same number can appear twice (and indeed does in our data). So our simulation model in R is simply

*x*must be a vector of items,*size*must be a number. Since 1:6 gives a vector of the numbers from 1 to 6, we can set x=1:6 and size=5. Here are 5 examples (note that the first 4 are equivalent, although the actual result will differ due to chance effects when sampling^{[1]}).sample(1:6, 5, TRUE)

## References[edit]

- ↑ call set.seed(1) before each chapter to get exactly the same results