Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

r
math
floor
communitycreator

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

harris910

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

RELATED TAGS

r
math
floor
communitycreator
RELATED COURSES

View all Courses

Keep Exploring