Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
r
logarithm
communitycreator

What is the log() function in R?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The log() function in R is used to obtain the logarithm (the natural logarithm, by default) of a given input numeric or complex vector.

Syntax

log(x, base)
Syntax for the log() function

Parameter value

The log() function takes the following parameter values:

  • x: This is the numeric or complex vector whose logarithm is to be obtained.
  • base: This is a positive or complex number that represents the base at which the logarithm of x is to be computed.

Return value

The log(0) function returns the logarithmic value in the specified base passed to it.

Code

# creating a numeric vector
x = 100
# taking the logarithm of x in base 2
log(x, 2)
# taking the logarithm of x in base 10
log(x, 10)
# taking the natural logarithm of x
log(x)
Implementing the log() function

Explanation

  • Line 2: We create a numeric vector x.
  • Line 5: We obtain the logarithm of x in base 2 using the log() function.
  • Line 8: We obtain the logarithm of x in base 10 using the log() function.
  • Line 11: We obtain the natural logarithm of x using the log() function.

RELATED TAGS

function
r
logarithm
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring