In addition to the basic arithmetic operations addition (+), subtraction (-), multiplication (*) and division (/), R has built-in standard mathematical functions. In the following section we take a look at some of them. Please note that in the course of this e-learning module we will encounter many more functions in R, we will even build user-defined functions by our own.

Absolute value function abs()

abs(3-12)
## [1] 9

Square root function sqrt()

sqrt(64)
## [1] 8

Exponentiation function exp()

exp(1)
## [1] 2.718282

log function (base \(e\)) log()

log(10)
## [1] 2.302585

log base 10 function log10()

log10(1000)
## [1] 3

Mathematical constant \(\pi\)

pi
## [1] 3.141593

Trigonometric functions sine, cosine, tangent (argument in radians) sin(), cos(), tan()

sin(pi/2)
## [1] 1
cos(pi/2)
## [1] 6.123234e-17
tan(0)
## [1] 0

Inverse trigonometric functions arc-sine, arc-cosine, arc-tangent asin(), acos(), atan()

asin(0)
## [1] 0
acos(1)
## [1] 0
atan(pi)
## [1] 1.262627

Round x to n decimal places round(x,n)

round(pi,2)
## [1] 3.14

Floor fuction (rounds down) floor()

floor(pi)
## [1] 3

Ceiling fuction (rounds up) ceiling()

ceiling(pi)
## [1] 4