# e in R

Euler’s number (also called e) is a very useful mathematical constant. It is irrational, and its value is approximately equal to 2.71828. It is used prominently in calculating and is the base of natural logarithms. It can be expressed as the sum of the following series: (`1+1/1!+1/2!+1/3!+1/4!+….`

).

Since R is used very highly for statistical analysis, it is essential to know how to calculate its value in a program. In R programming, we can compute the value of e using the `exp()`

function.

The `exp()`

function in R can return the exponential value of a number i.e. e^{x}. Here `x`

is passed to the function as a parameter. `x`

can also represent a numeric Vector. See the following example.

```
> exp(1)
[1] 2.718282
> exp(2)
[1] 7.389056
```

When we pass a numeric Vector to the function, it returns a Vector with all the elements’ exponential value. Example:

```
> x <- c(1,2,3)
> exp(x)
[1] 2.718282 7.389056 20.085537
```

Another interesting function available in R programming is `expm1()`

. It returns the exponential value of a number and subtracts one from the result. Just like the `exp()`

function, we can pass a number or a Numeric Vector. The following code snippet will show the details:

```
> x <- c(1,2,3)
> expm1(x)
[1] 1.718282 6.389056 19.085537
> expm1(1)
[1] 1.718282
```

**Manav Narula**

Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.

LinkedIn