Trusted answers to developer questions

harris910

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:

- A
for which the logarithm is to be calculated.number must be greater than 0 - The
`base`

of the is anlogarithm a number that must be greater than one *optional parameter*.

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

returns`NaN`

with a`warning`

error or`infinity`

.

#log without base a <- log(20); print(paste0("log(20): ", a)) #log with base b <- log(2,2); print(paste0("log(2,2): ", b)) #error outputs c <- log(0); print(paste0("log(0): ", c)) d <- log(-1); print(paste0("log(-1): ", d))

RELATED TAGS

r

math

logarithm

communitycreator

CONTRIBUTOR

harris910

RELATED COURSES

View all Courses

Keep Exploring

Related Courses