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:

Example
10 + 5

And the - operator is used for subtraction:

Example
10 - 5


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:

Example
max(5, 10, 15)

min(5, 10, 15)


sqrt()

The sqrt() function returns the square root of a number:

Example
sqrt(16)


abs()

The abs() function returns the absolute (positive) value of a number:

Example
abs(-4.7)


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:

Example
ceiling(1.4)

floor(1.4)