The log() function in R calculates the logarithm of a number to the base. log() calculates the natural logarithm of a number if the base is not specified by the user.
The following illustration shows the mathematical representation of the log() function.
log(number, base)
This function requires two parameters:
base of the log() returns the logarithm of a number to the base sent as a parameter.
Remember that the
log()function calculates the natural logarithm of a number if the base is not provided, i.e.,log(y,e).
If either of the parameters (i.e. base and number) is a negative number or zero, then
log()returnsNaNwith awarningerror orinfinity.
#log without basea <- log(20);print(paste0("log(20): ", a))#log with baseb <- log(2,2);print(paste0("log(2,2): ", b))#error outputsc <- log(0);print(paste0("log(0): ", c))d <- log(-1);print(paste0("log(-1): ", d))