This article about R’s rexp function is part of a series about generating random numbers using R. The rexp function can be used to simulate the exponential distribution. It is commonly used to model the expected lifetimes of an item.

Our earlier articles in this series dealt with:

- random selections from lists of discrete values
- Simulating the uniform distributions
- Simulating a normal distribution

### R and the Exponential Distribution

We’re going to start by introducing the rexp function and then discuss how to use it.

The **exponential distribution** is concerned with the amount of time until a specific event occurs. For example, the amount of time until the next rain storm likely has an exponential distribution. Other examples include the duration of long distance telephone calls, and the amount of time until an electronics component fails.

For an exponential distribution, there are few large values and more smaller values. For example, if we look at customer purchases in a store, there usually a few large customers and many smaller ones.

The exponential distribution is widely used in the field of reliability. Reliability deals with the amount of time a product lasts.

The exponential distribution is an appropriate model if the following conditions are true.

- X is the time (or distance) between events, with X > 0.
- The events occur independently. That is to say, the occurrence of one event does not affect the probability that a second event will occur.
- The rate at which events occur is constant for all intervals in the sample.
- Two events cannot occur at exactly the same instant.

R’s exp function generates values from the exponential distribution and return the results. The function takes two arguments:

- Number of observations you want to see
- The estimated rate of events for the distribution; this is usually 1/expected service life or wait time

The expected syntax is:

rexp(# observations, rate=rate )

For this example, lets assume we have six computers, each of which is expected to last an average of seven years. Can we simulate the expected failure dates for this set of machines?

rexp(6, 1/7) [1] 10.1491772 2.9553524 24.1631472 0.5969158 1.7017422 2.7811142

### Related Topics

This is part of our series on sampling in R. To hop ahead, select one of the following links:

- Random sample selections from a list of discrete values
- Simulating the uniform distributions
- Simulating a normal distribution
- Binomial trials
- The exponential distribution
- Simulating Poisson distributions