Logarithm and Power are two very important mathematical functions that help in the calculation of data that is growing exponentially with time.

First is the **Logarithm**, to which the general way to calculate the logarithm of the value in the base is with the ** log()** function which takes two arguments as value and base, by default it computes the natural logarithm and there are shortcuts for common and binary logarithm i.e. base 10 and 2. Value can be number or vector.

Second is the

**Power**, to calculate a base number raised to the power of exponent number. In this article, there are three methods shown to calculate the same i.e. base

^{exponent}.

#### Log Function in R

It is the inverse of the exponential function, where it represents the quantity that is the power to the fixed number(base) raised to give the given number. It returns the double value.

**Formula:**

If y = b

^{x}

then log_{b}y = x

**Example**:

if 100 = 10^{2}then log_{10}100 = 2

**List of various log() functions: **

The number is numeric or complex vector and the base is a positive or complex vector with the default value set to exp(1).

- The log function [log(number)] in R returns the natural logarithm i.e. base e.
log(10) = 2.302585

- [log10(number)] function returns the common logarithm i.e. base 10.
log10(10) := 1

- [log2(number)] returns the binary logarithm i.e. base 2.
log2(10) := 3.321928

- [log(number, b)] return the logarithm with base b.
log(10, 3) := 2.095903

- [log1p(number)] returns log(1+number) for number << 1 precisely.
log1p(10) := 2.397895

- [exp(number)] returns the exponential.
exp(10) := 22026.47

- [expm1(number)] returns the exp(number)-1 for number <<1 precisely.
expm1(10) := 22025.47

**Example:**

`# R program to illustrate use of log functions ` ` ` `x <` `-` `10` `base <` `-` `3` ` ` `# Computes natural logarithm ` `log(x) ` ` ` `# Computes common logarithm ` `log10(x) ` ` ` `# Computes binary logarithm ` `log2(x) ` ` ` `# Computes logarithm of ` `# x with base b ` `log(x, base) ` ` ` `# Computes accurately ` `# log(1+x) for x<<1 ` `log1p(x) ` ` ` `# Computes exponential ` `exp(x) ` ` ` `# Computes accurately ` `# exp(x)-1 for x<<1 ` `expm1(x) ` |

*chevron_right*

*filter_none*

**Output:**

[1] 2.302585 [1] 1 [1] 3.321928 [1] 2.095903 [1] 2.397895 [1] 22026.47 [1] 22025.47

#### Power Function

If there two numbers base and exponent, it finds x raised to the power of y i.e. x^{y}.

It returns double value. It needs two arguments:

x= floating point base valuey= floating point power value

** Example **:

10^{3}= 10*10*10 = 1000

`# R program to illustrate ` `# the use of Power Function ` `x <` `-` `10` `y <` `-` `3` ` ` `# 1st Method ` ``^`(x, y) ` ` ` `# 2nd Method ` `x^y ` ` ` `# 3rd Method ` `x` `*` `*` `y ` |

*chevron_right*

*filter_none*

**Output:**

[1] 1000 [1] 1000 [1] 1000

## Recommended Posts:

- Performing Logarithmic Computations in R Programming - log(), log10(), log1p(), and log2() Functions
- Compute the Logarithmic Derivative of the gamma Function in R Programming - digamma() Function
- Compute the Second Derivative of the Logarithmic value of the gamma Function in R Programming - trigamma() Function
- Inverse functions and composition of functions
- Fruitful Functions and Void Functions in Julia
- Compute the Parallel Minima and Maxima between Vectors in R Programming - pmin() and pmax() Functions
- Compute Beta Distribution in R Programming - dbeta(), pbeta(), qbeta(), and rbeta() Functions
- Exponential Distribution in R Programming - dexp(), pexp(), qexp(), and rexp() Functions
- Gamma Distribution in R Programming - dgamma(), pgamma(), qgamma(), and rgamma() Functions
- Functions in R Programming
- Recursive Functions in R Programming
- Conversion Functions in R Programming
- Poisson Functions in R Programming
- Poisson Functions in R Programming
- Applying User-defined Functions on Factor Levels of Dataset in R Programming - by() Function
- Get Summary of Results produced by Functions in R Programming - summary() Function
- Types of Functions in R Programming
- PHP | startsWith() and endsWith() Functions
- Difference between decodeURIComponent() and decodeURI() functions in JavaScript
- How to use Array Reverse Sort Functions for Integer and Strings in Golang?

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.