R provides many features for generating random numbers, especially compared to othe r languages. Built in to R, you can generate random numbers from many popular distributions which is helpful when simulating data. In this article, we will learn how to generate random variables from popular distributions in R.
Many of the methods to generate random variables are prefixed with a
r for random. For example, if we want to generate a random varaible form the normal distribution, we can use
rnorm, for random normal.
Each method will use default paramters unless you specify them. Here are many examples.
runif(1, min = -3, max = 3) # One uniform variate between -3 and +3 #>  2.49 rnorm(1) # One standard Normal variate #>  1.53 rnorm(1, mean = 100, sd = 15) # One Normal variate, mean 100 and SD 15 #>  114 rbinom(1, size = 10, prob = 0.5) # One binomial variate #>  5 rpois(1, lambda = 10) # One Poisson variate #>  12 rexp(1, rate = 0.1) # One exponential variate #>  3.14 rgamma(1, shape = 2, rate = 0.1) # One gamma variate #>  22.3