Calculate the Floor and Ceiling values in R Programming – floor() and ceiling() Function

floor() function in R Language returns the largest integer that is smaller than or equal to value passed to it as argument(i.e : rounds downs to the nearest integer).

Syntax: floor(x)

Parameter:
x: Value to be rounded off

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to calculate floor value 
    
# Using floor() method 
answer1 <- floor(1.2
answer2 <- floor(1.5
answer3 <- floor(2.6
answer4 <- floor(-2.6
    
print(answer1) 
print(answer2) 
print(answer3) 
print(answer4) 

chevron_right


Output:



1
1
2
-3

ceiling() Function

ceiling() function in R Language returns the smallest integer that is greater than or equal to the value passed to it as argument(i.e : rounds up to the nearest integer).

Syntax: ceiling(x)

Parameter:
x: Value to be rounded off

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to calculate ceiling value 
    
# Using ceiling() method 
answer1 <- ceiling(1.2
answer2 <- ceiling(1.5
answer3 <- ceiling(2.6
answer4 <- ceiling(-2.6
    
print(answer1) 
print(answer2) 
print(answer3) 
print(answer4) 

chevron_right


Output:

2
2
3
-2
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.