Generate Exponentially Distributed Data in R

Your goal

You need to randomly generate exponentially distributed data in R.

Step-by-step tutorial

We will use the rexp function from the stats package to do this.

The exponential distribution has a single rate parameter, \(\lambda > 0\). We'll generate 80 values using a rate of 1.07.

> data <- rexp(n=80, rate=1.07)
> data
 [1] 2.95872515 0.74376349 2.45500356 7.92149936 0.14378893 0.01403972
 [7] 0.48386561 2.49071981 0.89911478 0.20055251 0.08827906 0.47420892
[13] 0.15931666 2.97837211 0.10249459 0.07452636 0.60848994 0.40572475
[19] 0.98970603 3.42607258 2.95847666 1.05203583 0.58141164 1.49439355
[25] 0.87667611 1.16960892 1.58041952 0.50239239 0.07368946 0.31982013
[31] 0.70579707 0.66789062 0.96782102 0.48262220 0.20388254 1.95460632
[37] 4.52188035 0.30400189 1.69755573 0.67446493 2.09862772 0.58547015
[43] 0.16617593 0.23289439 1.26169881 1.65591571 0.57461038 1.36470128
[49] 0.28309416 0.10453184 0.03205463 2.72922546 1.53177163 2.23857930
[55] 0.82175924 0.01948763 0.18898184 0.77834726 4.83745497 0.68859965
[61] 0.74992798 1.20759740 2.86859683 0.06077270 0.14814702 2.08679538
[67] 0.41828594 0.49923465 1.25638388 0.19756476 1.26153775 0.38590719
[73] 0.47955284 0.86653072 0.50604602 0.21170861 0.50265006 2.74311415
[79] 3.63407436 0.42093356

We can use hist to generate a histogram for the distribution:

> hist(data)
Histogram of exponentially distributed data
Histogram of exponentially distributed data