The R ceiling method is one of the R Math function, which is used to return the smallest integer value which is greater than or equal to an individual number, or an expression. In this article, we will show you, How to use ceiling in R Programming language with an example.
R ceiling syntax
The basic syntax of the ceiling in R Programming language is as shown below:
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, ceiling function will return the ceiling value.
- If the numeric_Expression is positive or Negative Zero, ceiling function will return Zero
- numeric_Expression is not a number (NaN) then ceiling will return NaN.
- If the numeric_Expression is positive or negative infinity, function will return same
Following example will show 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
In this program, We are going to apply the ceiling function on List data and display the output. For this example, we are using the airquality data set provided by R
# ceiling in R example #Dataset We are going to use airquality # Applying Ceiling function on AIrquality Wind Data ceiling(airquality$Wind)
R 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 going to ceil 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, R Read CSV Function article to understand the steps involved in importing CSV file.
# 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)
From the above screenshot, you can observe that, 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
Thank You for Visiting Our Blog