Rounding off values in R Language – round() Function

** round()** function in R Language is used to round off values to a specific number of decimal value.

Syntax:round(x, digits)

Parameters:

x:Value to be round off

digits:Number of digits to which value has to be round off

**Example 1: Rounding off the values**

`# R program to illustrate ` `# round functiom ` ` ` `# Create example values ` `x1 <` `-` `1.2` `x2 <` `-` `1.8` `x3 <` `-` `-` `1.3` `x4 <` `-` `1.7` ` ` `# Apply round function ` `round` `(x1) ` `round` `(x2) ` `round` `(x3) ` `round` `(x4) ` ` ` `print` `(x1, x2, x3, x4) ` |

*chevron_right*

*filter_none*

**Output :**

1 2 -1 2

Here in the above code, we have round off the values with 4 data x1, x2, x3, and x4 using the function ** round()**, and printed the new values.

**Example 2: Rounding off to certain digits**

`# R program to illustrate ` `# round to a certain digit ` ` ` `# Create numeric with many digits ` `x2 <` `-` `3.14734343243` ` ` `# Round to three decimal places ` `round` `(x2, digits ` `=` `3` `) ` ` ` `print` `(x2) ` |

*chevron_right*

*filter_none*

**Output:**

3.147

Here in the above code, the value of a numeric vector is round off till 3 digits.