Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

R round Function

by suresh

The R round method is one of the Math functions, which round a specific number or an expression to the nearest value. Let us see how to use round in R Programming language with an example.

R round syntax

The syntax of the round in R Programming language is

# Round numeric_Expression to nearest value 
round(numeric_Expression)

# Round the decimal points to specified integer_value 
round(numeric_Expression, integer_value)

Numeric_Expression: It can be a numeric value or a valid numerical expression.

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

R round Function example 1

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

# round in R example

# Use round Function on Positive  Value
round(45.56)
round(525.4999)

# Use round Function on Negative values
round(-140.825)
round(-13.23)

# round Value of an Expression
round(140.986 + 122.456 - 220.4233 + 12.67)

# round Function on vectors
number <- c(-22.26, 456.94, 2.50, 2.51, -36.49, -813.111 , -525.123)
round(number)
R Round Function 1

round Function example 2

In this Program, We are going to round the decimal values of different data & display the output

# round in R example

# Use round Function on Positive  Value
round(45.565, 0)

# Round decimal points to 1 
round(525.419299, 1)
round(525.419299, 2)

# Use round Function on Negative values
round(-140.825, 2) 
round(-13.239, 2)

# round Value of an Expression
round((140.986 + 122.4563256 - 220.4233 + 12.67), 2)

# round Function on vectors
number <- c(-22.26, 456.94, 2.50, 2.591, -36.49, -813.111 , -525.123)
round(number, 1)
R Round Function 2

R round Function example 3

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

# round in R example

#Dataset We are going to use
airquality

# Applying round function on Airquality Wind Data
round(airquality$Wind)

round(airquality$Wind, 1)
R Round Function 3

round Function Example 4

The round function in R programming also allows you to round the numeric values in a database or table columns. In this example, We are going to round all the records present in [Standard Cost] and [Sales Amount] columns. For this, We are going to use the below-shown CSV file data.

TIP: Please refer to the R Read CSV Function article to understand the steps involved in importing the CSV file.

R round Function 5

R CODE

# round in R example

getwd()

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

# Applying round function on Standard Cost, and Sales Amount
round(product$StandardCost)
round(product$StandardCost, 1)

round(product$SalesAmount)
round(product$SalesAmount, 2)
R Round Function 4

Placed Under: R Programming

  • R Software Download
  • Install R Packages
  • Install R Software
  • Download & Install R Studio
  • R Arithmetic Operators
  • R Comparison Operators
  • R Logical Operators
  • R If Statement
  • R If Else Statement
  • R Else If Statement
  • R Nested If Else
  • R Switch Statement
  • R Break Statement
  • R Next Statement
  • R For Loop
  • R While Loop
  • R Repeat
  • R Vector
  • R Data Frame
  • R List
  • R Arrays
  • R Matrix
  • SQL Server R Services
  • R Read CSV Function
  • R Read table Function
  • R Barplot
  • R Boxplot
  • R Histogram
  • R Pie Chart
  • R Stacked Barplot
  • R Stem and Leaf Plot
  • R Mosaic Plot
  • R ggplot2 Boxplot
  • R ggplot2 Density Plot
  • R ggplot2 Dot Plot
  • R ggplot2 Histogram
  • R ggplot2 Jitter
  • R ggplot2 Line Plot
  • R ggplot2 Scatter Plot
  • R ggplot2 Violin Plot
  • Save R ggplot using ggsave
  • R Lattice Bar chart
  • R Lattice Scatter Plot
  • R Lattice Histogram
  • R Functions
  • R Recursive Functions
  • R abs Function
  • R sqrt Function
  • R ceiling Function
  • R floor Function
  • R round Function
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy