1. Learn
  2. /
  3. Courses
  4. /
  5. Sampling in R

Exercise

Generating random numbers

You've seen sample() and it's dplyr cousin, slice_sample() for generating pseudo-random numbers from a set of values. A related task is to generate random numbers that follow a statistical distribution, like the uniform distribution or the normal distribution.

Each random number generation function has a name beginning with "r". It's first argument is the number of numbers to generate, but other arguments are distribution-specific. Free hint: Try args(runif) and args(rnorm) to see what arguments you need to pass to those functions.

n_numbers is available and set to 5000; ggplot2 is loaded.

Instructions 1/3

undefined XP
    1
    2
    3

Complete the data frame of random numbers.

  • Generate n_numbers from a uniform distribution ranging from -3 to 3.
  • Generate n_numbers from a normal distribution with mean 5 and standard deviation 2.