Compute Density of the Distribution Function in R Programming dunif() Function (original) (raw)

Last Updated : 12 Jul, 2025

dunif() function in R Language is used to provide the density of the distribution function.

Syntax:dunif(x, min = 0, max = 1, log = FALSE)Parameters: x: represents vectormin, max: represents lower and upper limits of the distributionlog: represents logical value for probabilities

Example 1:

r `

Create vector of random deviation

u <- runif(20)

dunif(u) == u

print(dunif(u))

`

Output:

[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Example 2:

r `

Output to be present as PNG file

png(file = "dunifGFG.png")

Plot density

curve(dunif(x, min = 2, max = 6), 0, 8, ylim = c(0, 0.5), ylab = "f(x)", main = "Uniform Density f(x)")

Saving the file

dev.off()

`

Output: