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:
# 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) |
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:
# 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) |
Output:
2 2 3 -2


