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)
##  9

Square root function sqrt()

sqrt(64)
##  8

Exponentiation function exp()

exp(1)
##  2.718282

log function (base $$e$$) log()

log(10)
##  2.302585

log base 10 function log10()

log10(1000)
##  3

Mathematical constant $$\pi$$

pi
##  3.141593

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

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

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

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

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

round(pi,2)
##  3.14

Floor fuction (rounds down) floor()

floor(pi)
##  3

Ceiling fuction (rounds up) ceiling()

ceiling(pi)
##  4