四舍五入函数round

您所在的位置:网站首页 r语言中function函数的用法 四舍五入函数round

四舍五入函数round

2023-05-30 06:24| 来源: 网络整理| 查看: 265

四舍五入函数round

Rounding off the numbers can be achieved with round() in R. Round is one of the best ways to make numerical values more meaningful and to get more precise results in the analysis.

可以使用R中的round()将数字四舍五入。Round是使数值更有意义并在分析中获得更精确结果的最佳方法之一。

R offers the standard function round() to round off the numbers based on decimal values as well.

R提供了标准函数round(),也可以根据十进制值对数字进行四舍五入。

Well, in this tutorial we are going to round off the numbers in various aspects. Let’s roll!!!

好吧,在本教程中,我们将在各个方面对数字进行四舍五入。 来吧!!!

从R中的round()语法开始 (Starting with the syntax of round() in R)

The syntax of the round() function is given below,

round()函数的语法如下所示:

round(x,digits=0)

where,

哪里,

x -> numerical value or a vector available for round off

x->数值或可用于四舍五入的向量 digits -> This value represents the number of decimal points that you wish to have for the number

digits->此值表示您希望数字的小数位数 在R中使用round()舍入数字 (Rounding off the numbers using round() in R)

Some of you may know that R can accurately calculate up to 16 digits. But you always don’t need those 16 digits for your analysis. So using the round() function in R, you can easily round the numbers with specific decimal points as well.

你们中的某些人可能知道R可以准确计算最多16位数字。 但是,您始终不需要这16位数字进行分析。 因此,使用R中的round()函数,您也可以轻松地将数字与特定的小数点舍入。

四舍五入单个数值 (Round off a single numerical value )

Here we are going to round off a single value using the function round().

在这里,我们将使用功能round()舍入单个值。

As the below output shows, the digit value will indicate the decimal points.

如以下输出所示,数字值将指示小数点。

round(143.1234, digits = 0)

Output: 143

输出: 143

round(143.1234, digits = 1)

Output: 143.1

输出: 143.1

round(143.1234, digits = 2)

Output: 143.12

输出: 143.12

向量中的值取整 (Round Up Values in a Vector)

Now let’s round off the values stored in a vector.

现在,让我们四舍五入存储在vector中的值。

#creates a vector with multiple numerical values in it df


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3