Understanding data sampling in R
Sampling is a method to select a subset of data from a statistical population, which can use the characteristics of the population to estimate the whole population. The following recipe will demonstrate how to generate samples in R.
Getting ready
Make sure that you have an R working environment for the following recipe.
How to do it...
Perform the following steps to understand data sampling in R:
- In order to generate random samples of a given population, the user can simply use the
sample
function:> sample(1:10)
- To specify the number of items returned, the user can set the assigned value to the
size
argument:> sample(1:10, size = 5)
- Moreover, the sample can also generate Bernoulli trials by specifying
replace = TRUE ...
Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.