R Math
Simple Math
In R, you can use operators to perform common mathematical operations on numbers.
The + operator is used to add together two values:
And the - operator is used for subtraction:
You will learn more about available operators in our R Operators Tutorial.
Built-in Math Functions
R also has many built-in math functions that allows you to perform mathematical tasks on numbers.
For example, the min() and max() functions can be used to find the lowest or highest
number in a set:
sqrt()
The sqrt() function returns the square root of
a number:
abs()
The abs() function returns the absolute (positive) value of
a number:
ceiling() and floor()
The ceiling() function rounds a number upwards to
its nearest integer, and the floor()
function rounds a number downwards to its nearest integer, and returns the result: