Hello, readers! In this article, we will be focusing on **Uniform distribution in R – dunif(), punif(), qunif(), runif() functions** in detail.

So, let us begin!! ðŸ™‚

## First, what is Uniform Distribution?

In the domain of statistics, we do come across the various distribution of data variables such as :

**Normal Distribution****Binomial Distribution****Uniform Distribution**, etc.

Today, we will be focusing on Uniform Distribution in detail.

In simple terms, `Uniform Distribution `

is a probability based distribution wherein it happens to have equal chances of outcome to occur as a result. That is, it has equals chances for the probability to have the group values.

**For example**: Consider a scenario wherein we deal with the question that determines the probability of males or females who would opt for blue color for their car.

In such a scenario, with respect to the Uniform distribution of data, both males and females would have equal probability outcomes.

So equal chances of expecting either group of the probability values.

Within the Uniform Distribution, R programming provides us with the below functions to understand the variants in it.

`dunif() function`

`runif() function`

`qunif() function`

`punif() function`

Let us have a look at each variant one by one in the upcoming section!

## 1. R dunif() function

R `dunif() function`

enables us calculate the uniform probability density function for our passed set of values.

In this example, we have created a sequence of values between 0 to 50 using `seq()`

function. Further, we use dunif() function to get the uniform density probability value.

Before that, have a look at the below syntax!

```
dunif(data, min, max)
```

- data: The values on which density function is built.
- min: Specifies the minimum value to be set for the uniform density function.
- max: Depicts the maximum value for the uniform density function.

**Example:**

```
#Removed all the existing objects
rm(list = ls())
info = seq(0, 50, by = 1)
dta = dunif(info, min = 10, max = 25)
plot(dta,type="o")
```

**Output:**

As seen below, the density stays uniform from 0 upto the minimum value i.e. 10. Further to which, it scales up nearly to 1. And then, as soon as it reaches the maximum point i.e. 25, it again maintains the uniform density of values.

## 2. R punif() function

R `punif() function`

helps us estimate the uniform cumulative distribution function for the set of values.

In the below example, we use the same set of values as above! Further, punif() function calculates the cumulative frequency distribution for the set of values passed to it.

**Example:**

```
#Removed all the existing objects
rm(list = ls())
info = seq(0, 50, by = 1)
dta = punif(info, min = 10, max = 25)
plot(dta,type="o")
```

**Output:**

## 3. R qunif() function

R `qunif() function`

helps us to get the uniform quantile distribution probability values for the data values.

In this example, we have used qunif() function to get the quantile distribution values from the data values passed.

**Example:**

```
#Removed all the existing objects
rm(list = ls())
info = seq(0, 1, by = 0.04)
dta = qunif(info, min = 10, max = 25)
plot(dta,type="o")
```

**Output:**

## 4. R runif() function

Now, R `runif() function`

helps us get random numbers as usual but with a little twist. Using runif() function, we get a set of random numbers that are uniformly distributed i.e. follow an uniform distribution.

**Example:**

```
#Removed all the existing objects
rm(list = ls())
info = 20000
dta = runif(info, min = 10, max = 25)
hist(dta,breaks = 40,
main = "runif function",
xlim = c(0, 100))
```

**Output:**

As seen below, we can see the distribution of the random numbers. They follow an uniform distribution between the min value (10) and the maximum value (25), respectively.

## Conclusion

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

For more such posts related to R programming, Stay tuned.

Till then, Happy Learning!! ðŸ™‚