Floor and ceiling in R

Floor and ceiling in R is demonstrated with examples in this chapter

  • floor(x) function in R rounds to the nearest integer that’s smaller than x.
  • ceiling(x) function in R rounds to the nearest integer that’s larger than x

Example of floor() function in R:

# floor function in R

floor(125.2395)
output:
[1] 125

 

Example of floor() function in R for a vector:

# floor function in R for vector

floor(c(1.234,2.342,4.562,5.671,12.345,14.567))
output:
[1]  1  2  4  5  12  14

 

Example of ceiling() function in R:

# ceiling function in R

ceiling(125.2395)
output:
[1] 126

 

Example of ceiling() function in R for a vector:

# ceiling() function in R for vector

ceiling(c(1.234,2.342,4.562,5.671,12.345,14.567))
output:
[1]  2  3  5  6  13  15

previous small floor and ceiling in r                                                                                                                next small floor and ceiling in r