Using floor() and ceiling() function in R is easy. In this tutorial, we are focusing on the working and uses of these functions in R.

在R中使用floor()ceiling()函数很容易。 在本教程中,我们重点介绍R中这些功能的工作和使用。

Hello people, I hope you are doing good. As we know mathematical functions are the key components in the data analysis. Today we are discussing the mathematical functions such as the floor and ceiling in R. Let’s see how these functions will work.

大家好,希望您一切都好。 众所周知,数学函数是数据分析的关键组成部分。 今天,我们将讨论R中的地板和天花板等数学函数。让我们看看这些函数如何工作。

让我们从语法开始 (Let’s start with the syntax)

Floor(): Floor is a mathematical function in R, which returns the highest integer values which is smaller than the input value i.e. the output value will not be greater than the input value.

Floor(): Floor是R中的一个数学函数,它返回小于输入值的最大整数值,即输出值将不大于输入值。


floor(x)

Where:

哪里:

x = input vector or a value.

x =输入向量或值。

Ceiling(): The Ceiling function is also another mathematical function in R that will return the value which is nearest to the input value but it will be greater than the input value.

Ceiling(): Ceiling函数也是R中的另一个数学函数,它将返回最接近输入值但大于输入值的值。


ceiling(x)

Where x = input vector or a value

其中x =输入向量或值

Note: Both floor() and ceiling() values will round of the given input values. But floor function will round off the nearest values which should also be less than the input value. In the case of the ceiling function, it rounds off the nearest value which should also be greater than the input value.

注意: floor()和ceiling() 值将舍入给定的输入值。 但是下限功能将四舍五入到最接近的值,该值也应小于输入值。 对于上限功能,它将四舍五入到最接近的值,该值也应大于输入值。

I know that these definitions may create confusion in your mind. No worries, we are illustrating this with multiple examples for a better understanding as well.

我知道这些定义可能会使您困惑。 不用担心,我们还将通过多个示例进行说明,以便更好地理解。



R中的floor()函数 (The floor() function in R)

As we discussed above floor() function can return the nearest lesser value of the given input decimal. Let’s see how it works in the below sample.

正如我们上面讨论的,floor()函数可以返回给定输入小数的最接近的较小值。 在下面的示例中,让我们看看它是如何工作的。


#returns the nearest lesser value for the input
floor(5)

Output = 5

输出= 5


#returns the nearest lesser value for the input
floor(5.9)

Output = 5

输出= 5

Now, let’s see how we can compute the floor function for the negative value.

现在,让我们看看如何计算负值的下限函数。


#returns the nearest lesser value for the input
floor(-5.5)

Output = -6

输出= -6

In this case, -6 is less than -5.5. Hence the floor() function returned, the output as -6 as you can see above.

在这种情况下,-6小于-5.5。 因此,返回了floor()函数,如上所示,输出为-6。

As you may observe in the above samples and outputs, the floor() function returns the nearest value which is also less than the given input i.e. 5 and 5.9 the output returned as 5. Because 5 is the nearest value and also it is not greater than input values. For -5.5 the nearest value is -6.

如您在上面的示例和输出中所观察到的,floor()函数返回的最接近值也小于给定的输入,即5和5.9,输出返回为5。因为5是最接近的值,并且也不大于比输入值大。 对于-5.5,最接近的值为-6。



带向量的floor()函数 (The floor() function with a vector )

In this section, we will be focusing on the application of floor function on the vectors having values in it.

在本节中,我们将着重于地板函数在其中具有值的向量上的应用。


#creates a vector
df<-c(1.34,5.67,8.96,4,5.6678,0.00,6.55)#returns the nearest value which will not be greater than the input values
floor(df)

Output = 1 5 8 4 5 0 6

输出= 1 5 8 4 5 0 6

Now, let’s see how the floor() function works for the negative values.

现在,让我们看看floor()函数如何处理负值。


#creates a vector having nagetive values
df<-c(-3.45,6.7,-0.7,-5.5,4.4,-9.9)#returns the nearest value which will not be greater than the input values
floor(df)

Output = -4 6 -1 -6 4 -10

输出= -4 6 -1 -6 4 -10



带有表达式的floor()函数 (The floor() function with an expression)

In this section we are going to apply the floor function to an expression.

在本节中,我们将将floor函数应用于表达式。


#returns the final value which is nearest to input and also less than that.
floor(-3.55 + 2.566 - 8.99 + 3.44 - 5.98)

Output = -13

输出= -13

As shown above, the floor function will solve the expression or the equation and rounds off the output value.

如上所示,floor函数将求解表达式或方程式并四舍五入输出值。



带有数据框的floor()函数 (The floor() function with a data frame)

In this section, we are going to apply the floor() function to a data frame and find the nearest value of those values as well.

在本节中,我们将将floor()函数应用于数据框,并找到这些值的最接近值。

Let’s see how it works.

让我们看看它是如何工作的。


#returns the nearest value of the given input
floor(airquality$Wind)

Output =

输出=


[1] 7 8 12 11 14 14 8 13 20 8 6 9 9 10 13 11 12 18 11 9 9 16 9 12
[25] 16 14 8 12 14 5 7 8 9 16 9 8 14 9 6 13 11 10 9 8 13 11 14 20
[49] 9 11 10 6 1 4 6 8 8 10 11 14 8 4 9 9 10 4 10 5 6 5 7 8
[73] 14 14 14 14 6 10 6 5 11 6 9 11 8 8 8 12 7 7 7 9 6 13 7 6
[97] 7 4 4 10 8 8 11 11 11 9 11 10 6 7 10 10 15 14 12 9 3 8 5 9
[121] 2 6 6 6 5 2 4 7 15 10 10 10 9 14 15 6 10 11 6 13 10 10 8 12
[145] 9 10 10 16 6 13 14 8 11


R中的ceiling()函数 (ceiling() function in R)

As we discussed in the initial phases of this tutorial, the ceiling() function will return the higher integer for the given decimal input.

正如我们在本教程的初始阶段所讨论的,ceiling()函数将为给定的十进制输入返回较高的整数。

Let’s see how ceiling works.

让我们看看天花板是如何工作的。


#returns the nearest value which is greater than the input
ceiling(2.456)

Output = 3

输出= 3


#returns the nearest value which is greater than the input
ceiling(-5.98)

Output = -5

输出= -5

As you can observe in the above outputs, the ceiling() function is returning the nearest highest value to the given input.

从上面的输出中可以看到,ceiling()函数将最接近的最大值返回给定的输入。



带矢量的ceiling()函数 (ceiling() function with a vector)

In this section, let’s see how the ceiling function can be applied to a vector having multiple values.

在本节中,让我们看看如何将上限函数应用于具有多个值的向量。


#creates a vector
df<-c(1.34,5.66,7.89,9.54)#returns the nearest value which is greater than the input
ceiling(df)

Output = 2 6 8 10

输出= 2 6 8 10

For negative values in a vector.

对于向量中的负值 。


#creates a vector
df<-c(-2.34,5.67,-9.87,-6.77)#returns the nearest value which is greater than the input
ceiling(df)

Output = -2 6 -9 -6

输出= -2 6 -9 -6



带表达式的ceiling()函数 (ceiling() function with an expression)

In this section, we are going to apply the ceiling function to an expression. Let’s see how it works.

在本节中,我们将把上限函数应用于表达式。 让我们看看它是如何工作的。


#returns the nearest value which is greater than the input
ceiling(-3.45 + 5.678 - 7.890 - 4.678)

Output = -10

输出= -10


#returns the nearest value which is greater than the input
ceiling(-3.45 + 5.678 - 7.890 - 4.678 + 6.89000 + 2.456 + 5.678)

Output = 5

输出= 5



带数据框的ceiling()函数 (ceiling() function with a data frame)

Well, we have applied the ceiling function to single values, multiple values, vectors, and expressions also. It’s time to apply to the ceiling () function to a data frame. Let’s use the airquality data set for this purpose.

好吧,我们已经将上限函数应用于单个值,多个值,向量和表达式。 现在是将上限()函数应用于数据框的时候了。 为此,我们使用空气质量数据集。

This is the data frame of the airquality data set, which is available in R studio by default.

这是空气质量数据集的数据框,默认情况下在R studio中可用。


#returns the nearest value which is greater than the input
ceiling(airquality$Wind)

Output =

输出=


[1] 8 8 13 12 15 15 9 14 21 9 7 10 10 11 14 12 12 19 12 10 10 17 10 12
[25] 17 15 8 12 15 6 8 9 10 17 10 9 15 10 7 14 12 11 10 8 14 12 15 21
[49] 10 12 11 7 2 5 7 8 8 11 12 15 8 5 10 10 11 5 11 6 7 6 8 9
[73] 15 15 15 15 7 11 7 6 12 7 10 12 9 8 9 12 8 8 8 10 7 14 8 7
[97] 8 5 4 11 8 9 12 12 12 10 12 11 7 8 11 11 16 15 13 10 4 8 6 10
[121] 3 7 7 7 6 3 5 8 16 11 11 11 10 15 16 7 11 12 7 14 11 11 8 13
[145] 10 11 11 17 7 14 15 8 12

You can see that the ceiling function returned the nearest highest value of the given input values. Its how the ceiling() function works in R.

您可以看到ceiling函数返回给定输入值的最接近的最大值。 它的ceiling()函数在R中的工作方式。



加起来 (Summing up)

R offers the mathematical functions such as the floor() and ceiling() to compute the mathematical operations such as finding the nearest values of the input.

R提供了数学函数(例如floor()和ceiling())来计算数学运算,例如查找输入的最接近值。

In this tutorial, we have discussed the working of floor and ceiling functions. The floor will return the nearest lower value of the given input and on the other side, the ceiling function will return the nearest higher value of the given input as illustrated in the above samples.

在本教程中,我们讨论了地板和天花板功能的工作。 地板将返回给定输入的最接近的较低值,而在另一侧,上限功能将返回给定输入的最接近的较高值,如上述示例所示。

That’s all about the floor() and ceiling() functions in R. Happy flooring and ceiling!!!

这是所有关于地板()和上限()在R. 快乐职能地板和天花板!

More study: Floor in R – R documentation and ceiling in R – stat.ethz

更多研究: R – R文档中的 下限和R – stat.ethz中的上限

翻译自: https://www.journaldev.com/40991/floor-ceiling-function-in-r

如何在R中使用floor()和ceiling()函数相关推荐

  1. 如何在 R 中使用 tabulate() 和table() 函数计算整数出现次数

    R 中的tabulate()函数可用于计算向量中整数值的出现次数. 示例 1:计算向量中的整数出现次数 以下代码显示了如何使用tabulate()函数计算给定向量中整数的出现次数: data < ...

  2. csv文件示例_如何在R中使用数据框和CSV文件-带有示例的详细介绍

    csv文件示例 Welcome! If you want to start diving into data science and statistics, then data frames, CSV ...

  3. 如何在R中正确使用列表?

    本文翻译自:How to Correctly Use Lists in R? Brief background: Many (most?) contemporary programming langu ...

  4. rstudio r语言_如何在R中接受用户输入?

    rstudio r语言 Taking a user input is very simple in R using readline() function. In this tutorial, we ...

  5. 如何在 R 中执行 Wald 测试

    Wald 检验可用于测试模型中的一个或多个参数是否等于某些值. 此检验通常用于确定回归模型中的一个或多个预测变量是否等于零. 我们对此测试使用以下无效假设和替代假设: H 0:一些预测变量都等于零. ...

  6. 如何在 R 中计算条件概率

    假设事件B已经发生,事件A发生的条件概率计算如下: P(A|B) = P(A∩B) / P(B) 在哪里: P(A∩B) = 事件A 和事件 B 同时发生 的概率 . P(B) = 事件 B 发生的概 ...

  7. 如何在 R 中计算调整后的 R 平方

    如果有什么问题和项目作业关于R语言,可以微信call我:RunsenLiu R 平方,通常写成 R 2,是响应变量中的方差比例,它可以由线性回归模型中的预测变量来解释. R-squared 的值可以在 ...

  8. 如何在 R 中读取 Zip 文件

    您可以使用以下基本语法将 ZIP 文件读入 R: library(readr)#import data1.csv located within my_data.zip df <- read_cs ...

  9. 如何在 R 中找到 F 临界值

    当您进行 F 检验时,您将获得 F 统计量作为结果.要确定 F 检验的结果是否具有统计显着性,可以将 F 统计量与 F 临界值进行比较.如果 F 统计量大于 F 临界值,则检验结果具有统计显着性. F ...

最新文章

  1. A+B/A*B求A和B
  2. 预览文章: c++ primer学习笔记,二:标准库类型
  3. php二维数组中的查找,PHP实现二维数组中的查找算法小结
  4. 软件需求说明书谁负责写_新手入门软件测试需要掌握哪些知识点?
  5. Windows系统下,使用Emacs+Putty操作远程机器
  6. zynq开发系列4:MIO按键中断控制LED
  7. android模拟鼠标点击事件给控件,Android使用模拟鼠标拖动操作
  8. AJAX,JSON 夜鹰
  9. mysql test 映射到实体_第80天:Python 操作 MySQL
  10. 计算机显示器刷新率怎么调,电脑显示器刷新率如何设置,免费教你如何快手设置刷新率...
  11. 【万物互联支持一碰传、多屏协同】第三方非华为电脑安装华为电脑管家
  12. 想用linux又想windows,Linux对Windows说:停止吵架,和平共处
  13. Ubuntu下载常用软件和使用Caffe时的常见问题
  14. 【第一组】第二次例会会议记录
  15. java企查查爬_爬取企查查热搜
  16. 三星会在泰泽大会上展示meego系统的新机么?
  17. ros语音识别:pocketsphinx_continuous工作正常而gst-pocketsphinx不能识别相同语音的问题。
  18. python矩阵变成图片_Python图片转换成矩阵,矩阵数据转换成图片
  19. 报错ERROR:Skipping MapperFactoryBean with name 'xxxMapper' and 'xxx.xxx.xxx.mapper.xxxxxMapper'
  20. ios 模拟器如何模拟多点触控

热门文章

  1. 近视能恢复吗 我半年的体会
  2. 选择WMS仓库管理系统之前,企业应该准备些什么
  3. centos系统性能监控常用软件介绍
  4. 群体智能优化算法之细菌觅食优化算法(Bacterial Foraging Optimization Algorithm,BFOA)
  5. 1095:数1的个数(信奥)
  6. mysql rollback to,MySQL存储过程SAVEPOINT ROLLBACK to
  7. 如何建设一个优质的企业网站?
  8. 2018-2019(1)教学随笔
  9. github前端插件大全
  10. 代号:生机迟迟不上线?腾讯另一款沙盒生存手游我的起源却今日开测