Understanding uniform distributions
If we roll a fair dice, the likelihood of drawing any side is equal. By plotting the samples in a bar plot, we can see bars with equal heights. This type of distribution is known as uniform distribution. In this recipe, we will introduce how to generate samples from a uniform 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 a sample from uniform distribution:
- First, we can create samples from uniform distribution by using the
runif
function:> set.seed(123) > uniform <- runif(n = 1000, min = 0, max = 1)
- We can then make a histogram plot out of the samples from the uniform distribution:
> hist(uniform, main ...
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.