log()
log(x, base = exp(1)) Returns:
numeric · Updated March 13, 2026 · Base Functions math log logarithm base
The log() function computes the natural logarithm (base e) of a number. The natural logarithm uses Euler’s number e as its base.
Syntax
log(x, base = exp(1))
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
x | numeric | — | A numeric vector or scalar |
base | numeric | exp(1) | The base for the logarithm |
Examples
Basic usage
# Natural log of e is 1
log(exp(1))
# [1] 1
# Natural log of 1 is 0
log(1)
# [1] 0
# Natural log of values > 1
log(1:5)
# [1] 0.000000 0.693147 1.098612 1.386294 1.609438
# Natural log of values < 1 (negative result)
log(0.5)
# [1] -0.6931472
Using different bases
# Log base 2
log(8, base = 2)
# [1] 3
# Log base 10
log(100, base = 10)
# [1] 2
Common bases shortcuts
# log10() is log(x, base = 10)
log10(100)
# [1] 2
# log2() is log(x, base = 2)
log2(8)
# [1] 3
Common Patterns
Log-transforming skewed data
# Log-transform skewed distribution
x <- c(1, 10, 100, 1000, 10000)
log(x)
# [1] 0.000000 2.302585 4.605170 6.907755 9.210340
Geometric mean
# Geometric mean using exp(mean(log(x)))
x <- c(2, 4, 8)
exp(mean(log(x)))
# [1] 4
Log-odds to probability
# Convert log-odds to probability
log_odds <- 0.5
exp(log_odds) / (1 + exp(log_odds))
# [1] 0.6224593