Sampling from a normal distribution

From observing real-world data, we may determine that most data follows a normal distribution. That is to say, when we use a density curve (or histogram) to plot the data, we should see it as bell-shaped. As this kind of distribution is so commonly seen in nature or social science, scientists often use a normal distribution to represent real-value random variables from an unknown distribution. In this recipe, we will demonstrate how R generates samples from a normal distribution.

Getting ready

In this recipe, you need to prepare your environment with R installed.

How to do it…

Please perform the following steps to generate samples from a normal distribution:

  1. First, you can use the rnorm function to generate 30 and ...

Get R for Data Science Cookbook 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.