R Tutorial R Charts & Graphs R Statistics R References

R - ceiling() Function



The R ceiling() function returns the next highest integer value by rounding up the specified number, if necessary. In other words, it rounds the fraction UP of the given number. In special cases it returns the following:

  • If the argument value is already an integer, then the result is the same as the argument.
  • If the argument is NaN or infinity, then the result is the same as the argument.

Syntax

ceiling(x)

Parameters

x Required. Specify column to compute on.

Return Value

Returns the next highest integer value by rounding UP the specified number, if necessary.

Example:

In the example below, ceiling() function is used to round the fraction UP of the specified value.

#operating on single element atomic vector
print(ceiling(-1))
print(ceiling(0.5))
print(ceiling(1.4))

cat("\nOperating on vector\n")
#operating on vector
v <- c(10.3, 10.5, 10.7, -10.3, -10.5, -10.7)
print(ceiling(v))

cat("\nOperating on matrix\n")
#operating on matrix
m <- matrix(c(-10.3, -10.5, -10.7, 100.2, Inf, NaN), nrow=2)
print(ceiling(m))

cat("\nOperating on first column of matrix\n")
#operating on first column of matrix
print(ceiling(m[,1]))

The output of the above code will be:

[1] -1
[1] 1
[1] 2

Operating on vector
[1]  11  11  11 -10 -10 -10

Operating on matrix
     [,1] [,2] [,3]
[1,]  -10  -10  Inf
[2,]  -10  101  NaN

Operating on first column of matrix
[1] -10 -10

❮ R Math Functions