The “rnorm” Function in R

  • Package: Base R (no specific package required)

  • Purpose: Generates random numbers from a normal distribution.

  • General Class: Random Number Generation

  • Required Argument(s):

    • n: The number of random values to generate.

  • Notable Optional Arguments:

    • mean: The mean of the normal distribution. The default is 0.

    • sd or sigma: The standard deviation of the normal distribution. The default is 1.

  • Example:

  • # Generate 100 random values from a normal distribution with a mean of 5 and standard deviation of 2
    random_values <- rnorm(n = 100, mean = 5, sd = 2)
    print(random_values)

  • In this example, the rnorm function is used to generate 100 random values from a normal distribution with a mean of 5 and a standard deviation of 2. The generated values are then printed to the console.

Previous
Previous

The “runif” Function in R

Next
Next

The “rbinom” Function in R