How to calculate floor() of a value in R?

The floor() function in R returns the highest number that is less than or equal to a number set as a parameter.

Figure 1 below shows the mathematical representation of the floor() function and the corresponding expression in R.

Figure 1: Mathematical representation of floor() function and the corresponding expression in R

Syntax


floor(number)

Parameter

This function requires a number to round down as a parameter.

Return value

floor() returns the largest number that is less than or equal to a number set as a parameter.

Code

#Positive number
a <- floor(10);
print(paste0("floor(10): ", a))
b <- floor(5.3);
print(paste0("floor(5.3): ", b))
#negative number
c <- floor(-10);
print(paste0("floor(-10): ", c))
d <- floor(-5.3);
print(paste0("floor(-5.3): ", d))

Free Resources