Normal Distribution in R [With Easy Examples]

Filed Under: R Programming
Normal Distribution In R

Hello, readers! In this article, we will be focusing on Normal Distribution in R and discuss the dnorm(), rnorm(), pnorm() and qnorm() functions in detail.

So, let us begin!!

What is Normal Distribution in R?

In terms of statistics, we deal with various kinds of probability distributions such as Normal Distribution, Uniform Distribution, etc.

Basically, the distribution of data in statistical terms estimates the association of the data with respect to the mean and other aspects of the data.

In Normal Distribution, the values are shaped properly i.e. they follow a continuous type of probability distribution all over the curve. It gives us a probability function that describes the way all the values are distributed. Usually, in a normal probability distribution of data, all the data are close to the center peak of the distribution.

Let us now focus on the variants of Normal Distribution which complies of the following:

  • dnorm() function
  • qnorm() function
  • rnorm() function
  • pnorm() function

So. let us begin!!

1. R dnorm() function

R dnorm() function helps us understand the distribution of the data in terms of probability density.

In the below example, we have used dnorm() function to get the probability density of values ranged between 1 – 10.

Have a look at the below syntax!

dnorm(data, mean, standard-deviation)
  • mean (optional): The mean value according to which the aligning of data occur for the data.
  • standard-deviation (optional): The data values would follow the standard deviation as mentioned in the argument list.


#Removed all the existing objects
rm(list = ls())
dta = dnorm(1:10, 4.5)


Here, the data values would follow a mean of 4.5 and the below distribution gives us an idea of the height of the probability density for the data.


> print(dta)
 [1] 8.726827e-04 1.752830e-02 1.295176e-01 3.520653e-01 3.520653e-01 1.295176e-01 1.752830e-02 8.726827e-04 1.598374e-05
[10] 1.076976e-07
Dnorm Function
dnorm Function

2. R pnorm() function

The R pnorm() function helps us attain the Cumulative Distribution of the data values in terms of probability.

So, it helps us with the probability of the normally distributed values as a value that is less than or equal to the mentioned values in the argument list.


#Removed all the existing objects
rm(list = ls())

info = c(1,2,3,4,5,6,7,8,9,10)
dta = pnorm(1:10, 4.5)



> print(dta)
 [1] 0.0002326291 0.0062096653 0.0668072013 0.3085375387 0.6914624613 0.9331927987 0.9937903347 0.9997673709 0.9999966023
[10] 0.9999999810
Pnorm Function
pnorm Function

3. R qnorm() function

R qnorm() function works in terms of the quantile function for the normally distributed data values. That is, it gives us data values in terms of the quantile probability that has the cumulative value matching the probability value.


#Removed all the existing objects
rm(list = ls())

info = seq(0, 1, by = 0.04)
dta = qnorm(info, 2)



> print(dta)
 [1]      -Inf 0.2493139 0.5949284 0.8250132 1.0055421 1.1583788 1.2936974 1.4171585 1.5323012 1.6415412 1.7466529
[12] 1.8490308 1.9498464 2.0501536 2.1509692 2.2533471 2.3584588 2.4676988 2.5828415 2.7063026 2.8416212 2.9944579
[23] 3.1749868 3.4050716 3.7506861       Inf
Qnorm Function
qnorm Function

4. rnorm() function in R

R rnorm() function gets us the random numbers with some specified mean and standard deviation values that are normally distributed in nature.


#Removed all the existing objects
rm(list = ls())

dta = rnorm(60, 2)

hist(dta, main="Rnorm Distribution")


As seen in the below histogram, the values generated from rnorm() function follows a normal distribution!

> print(dta)
 [1]  2.8616566  2.1762027  2.0089277  1.6712073  3.1367160  1.0530471  1.9594425  2.0119708  2.0798368  2.2305375
[11]  3.0299909  1.6733021  0.4444830  3.5719529  2.4590993  1.6092075  1.4478063  2.7230136  1.1336591  4.5034106
[21]  2.2843498  1.0186055  3.5859836  3.2889705  4.2408520  3.0277005  1.4821509  3.5363188  1.3043573  2.3681723
[31]  2.2314273  1.1745603  2.5737279  3.6843708  2.5191612  1.7932707  1.3593706  1.1871905  1.7500578 -0.8554127
[41]  1.8982584  2.6043514  1.3884122  2.6030561  1.3569914  3.2852826  2.1910881  2.8166128  1.1085651  1.4220668
[51]  1.2162924  2.3394958  1.8520521 -0.6903053  1.4856287  3.6560399  3.5229254  4.6193493  1.2126980  3.2726076
Rnorm Function
rnorm Function


By this, we have come to the end of this topic. Now, feel free to comment below, in case you come across any questions.

And for more such posts related to R programming, Stay tuned with us!

Till then, Happy Learning!! 馃檪

Leave a Reply

Your email address will not be published. Required fields are marked *

Generic selectors
Exact matches only
Search in title
Search in content