R ceiling Function

The R ceiling method is one of the R Math function that returns the smallest integer value, which is greater than or equal to a specific number, or an expression. Let us see how to use the ceiling in the R Programming language with an example.

R ceiling syntax

The syntax of the ceiling in R Programming language is


Numeric_Expression: It can be a numeric value or a valid numerical expression for which you want to find the square root.

  • If the numeric_Expression is positive or Negative numeric value, the ceiling function returns the ceiling value.
  • If it is positive or Negative Zero, ceiling function returns Zero
  • numeric_Expression is not a number (NaN), then the ceiling returns NaN.
  • If the numeric_Expression is positive or negative infinity, the function returns the same.

The following ceiling example shows you the same.

# ceiling in R example

# Use Ceiling Function on both Positive and negative zeros

# Use Ceiling Function on Not a Number

# Ceiling Numbers of +ve and -ve Infinity

# Use Ceiling Function on Characters
ceiling("Tutorial Gateway")
R ceiling Function 1

R ceiling Function example 1

In this program, We are going to find the ceiling values of different data and display the output

# ceiling in R example

# Use Ceiling Function on Positive  Value

# Use Ceiling Function on Negative values

# Ceiling Value of an Expression
ceiling(10.986 + 12.456 - 20.423 + 1.67)

# Ceiling Function on vectors
number <- c(-25.26, 256.94, -36.42, -813.111 , -525.123)
R ceiling Function 2

R ceiling Function example 2

In this program, We are going to apply the ceiling function on List data and display the output. For this R Programming example, we are using the airquality data set provided by R

# ceiling in R example

#Dataset We are going to use

# Applying Ceiling function on AIrquality Wind Data
R ceiling Function 3

ceiling Function Example 3

The ceiling function in R programming also allows you to ceil the numeric values in a database or table columns. In this example, We are ceiling all the records present in [Standard Cost] and [Sales Amount] columns.

For this, We are going to use the below-shown CSV data, and I suggest you refer to the R Read CSV Function article to import the CSV file.

R ceiling Function 5

From the below screenshot, you can observe that the ceiling function is returning the smallest integer value, which is greater than or equal to the values in the Standard Cost and Sales Amount column.

# ceiling in R example


#Datat We are going to use
product <- read.csv("Product_Data.csv", TRUE, sep = ",")

# Applying Ceiling function on Standard Cost, and Sales Amount
R ceiling Function 4