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 ceiling(0) ceiling(-0) # Use Ceiling Function on Not a Number ceiling(NaN) ceiling(-NaN) # Ceiling Numbers of +ve and -ve Infinity ceiling(Inf) ceiling(-Inf) # Use Ceiling Function on Characters ceiling("Tutorial Gateway")
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 ceiling(645.956) ceiling(25.225) # Use Ceiling Function on Negative values ceiling(-10.285) ceiling(-123.987) # 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) ceiling(number)
R ceiling Function example 2
# ceiling in R example #Dataset We are going to use airquality # Applying Ceiling function on AIrquality Wind Data ceiling(airquality$Wind)
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.
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 getwd() #Datat We are going to use product <- read.csv("Product_Data.csv", TRUE, sep = ",") print(product) # Applying Ceiling function on Standard Cost, and Sales Amount ceiling(product$StandardCost) ceiling(product$SalesAmount)