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: (
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 in R can return the exponential value of a number i.e.
x is passed to the function as a parameter.
x can also represent a numeric Vector. The example below will make it clear:
> exp(1)  2.718282 > exp(2)  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)  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.718282 6.389056 19.085537 > expm1(1)  1.718282