R - log10() Function
The R log10() function returns the base-10 logarithm of a given number. In special cases it returns the following:
- If the argument is NaN or less than zero, then the result is NaN.
- If the argument is positive infinity, then the result is positive infinity.
- If the argument is zero, then the result is negative infinity.
Syntax
log10(x)
Parameters
x |
Required. Specify column to compute on. |
Return Value
Returns the base-10 logarithm of the value.
Example:
In the example below, log10() function is used to calculate the base-10 logarithm of a given number.
#operating on single element atomic vector print(log10(0)) print(log10(0.5)) print(log10(1)) cat("\nOperating on vector\n") #operating on vector v <- c(5, 10, 50) print(log10(v)) cat("\nOperating on matrix\n") #operating on matrix m <- matrix(c(1, 10, 50, 100, 500, NaN), nrow=2) print(log10(m)) cat("\nOperating on first column of matrix\n") #operating on first column of matrix print(log10(m[,1]))
The output of the above code will be:
[1] -Inf [1] -0.30103 [1] 0 Operating on vector [1] 0.69897 1.00000 1.69897 Operating on matrix [,1] [,2] [,3] [1,] 0 1.69897 2.69897 [2,] 1 2.00000 NaN Operating on first column of matrix [1] 0 1
❮ R Math Functions