R ln() Function (SciViews Package)

The ln() function from the SciViews package calculates the natural log of the input vector.

R does not come with an ln() function but provides a log10() function.

Syntax

``````ln(x)

ln1p()

lg()

lg1p(x)

E

lb()``````

Parameters

x: It is a numeric or complex vector.

Return value

It returns the natural logarithm of a value.

Example

``````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).

Plotting

``````# Load necessary libraries
library(ggplot2)

# Define the range and compute the natural logarithm values
x_values <- seq(0.01, 10, by=0.01)
y_values <- ln(x_values)

# Create the plot
plot <- ggplot(data.frame(x=x_values, y=y_values), aes(x=x, y=y)) +
geom_line(color="red") +
ggtitle("Natural Logarithm Function") +
xlab("x") +
ylab("ln(x)") +
theme_minimal()

# Display the plot
plot
``````

Output

You can see that we plotted a line chart displaying the natural logarithm function.