The natural log in mathematics is the logarithm to the base of the number e, which is the inverse function of an exponential function. Natural logs are specific logarithms used to solve time and growth problems.

**Natural log in R**

To **calculate** the **natural** **log** in **R**, use the **ln()** function. The **ln()** is a SciViews package function that takes a vector as an argument and returns the natural log of the input vector. The default setting of the ln() function is to return the natural logarithm of a value.

We define **ln()** and **ln1p()** as wrappers for log()“ with defaultbase = exp(1) argument and for log1p(), respectively. The lg1p() is a convenient way to use the optimized code to calculate the logarithm of x + 1 but return the result in the base 10 logarithms.

```
ln(x)
ln1p()
lg()
lg1p(x)
E
lb()
```

**Arguments**

**x:** It is a numeric or complex vector.

**Examples**

R does not come with an() function. However, r provides log10() function. To use the ln() function, use the **SciViews** package.

```
library("SciViews")
ln(exp(2))
ln1p(c(0, 1, 11, 110))
lg(11 ^ 3)
lg1p(c(0, 1, 11, 110))
E ^ 4
lb(1:4)
```

**Output**

```
[1] 2
[1] 0.0000000 0.6931472 2.4849066 4.7095302
[1] 3.124178
[1] 0.000000 0.301030 1.079181 2.045323
[1] 54.59815
[1] 0.000000 1.000000 1.584963 2.000000
```

E is the Euler constant and is equal to exp(1).

**log in R**

The log() is a built-in R function that calculates logarithms of input values. The **log()** method calculates natural logarithms by default.

**Syntax**

`log(x, base)`

**Arguments**

**x –** It is numeric to which log has to be computed

**base –** It is the base of the log.

**Example**

Let’s find the natural log of 19 using the log() function.

```
data <- log(19)
cat("The natural logarithm of 19 is: ")
cat(data)
```

**Output**

`The natural logarithm of 19 is: 2.944439`

The natural log(ln) function is frequently used to rescale data for statistical and graphical analysis.

That is it for the ln() function in R.

Krunal Lathiya is an Information Technology Engineer by education and web developer by profession. He has worked with many back-end platforms, including Node.js, PHP, and Python. In addition, Krunal has excellent knowledge of Data Science and Machine Learning, and he is an expert in R Language. Krunal has written many programming blogs, which showcases his vast expertise in this field.