log()
   get_help() docs


Description

The log() function comes with R and is part of the Base R {base} package.

We use this function to calculate the log of a number or numeric array. By default, the function calculates the natural log (base e). Provide a second argument to change the base.

Conceptual Usage

log(number to get the natural log of)

log(number to get the base x log of, x)

log(numeric array to get natural log of all its values)

Examples

# Find the natural log of 107
log(107)
## [1] 4.672829


# Find the natural log of a defined variable
x <- 107
log(x)
## [1] 4.672829


# Find the log of 107 in base 5
log(107, 5)
## [1] 2.903392


# Find the natural log of all values in an array
log( c(100, 110, 120) )
## [1] 4.605170 4.700480 4.787492


# Find the log in base 2 of all values in an array
my_array <- c(100, 110, 120)
log( my_array, 2 )
## [1] 6.643856 6.781360 6.906891