Get startedGet started for free

Sampling from the population

In this lab we have access to the entire population. In real life, this is rarely the case. Often we gather information by taking a sample from a population. In the lectures, you've become familiar with the male beard length (in millimeters) of hipsters in Scandinavia. In this lab, we will be working with this example.

If we were interested in estimating the average male beard length of hipsters in Scandinavia, in R we can use the sample() function to sample from the population. For instance, to sample 50 inhabitants from our Scandinavian male hipster population which is included in the variable scandinavia_data, we could do the following: sample(scandinavia_data, size = 50). This command collects a simple random sample of size 50. If we didn't have access to the entire male hipster Scandinavian population, working with these 50 inhabitants would be considerably simpler than having to go through the entire Scandinavian male hipster population.

This exercise is part of the course

Basic Statistics

View Course

Exercise instructions

  • Make sure not to remove the set.seed(11225) code. This makes sure that you will get the same results as the solution code
  • Sample 100 values from the dataset scandinavia_data and store this in a variable first_sample
  • Calculate the mean of first sample and print the result.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# variable scandinavia_data contains the beard lengths of scandinavian male population
set.seed(11225)
Edit and Run Code