‘/’ 运算符和 ‘%/%’ 运算符在R编程语言中有什么区别?

huangapple go评论166阅读模式
英文:

What is the difference between '/' operator and "%/%" operator in r programming language?

问题

第三行和第四行代码有什么不同?

英文:

I came across below code

v <- c( 2,5.5,6)
t <- c(8, 3, 4)
print(v/t)
print(v%/%t)

In what way 3rd and 4th lines of code are different?

答案1

得分: 5

/ 表示通常的除法。

关于 %/%文档 表示:

%% 表示 x mod y%/% 表示整数除法。除非 y == 0,可以保证 x == (x %% y) + y * (x %/% y)(最多存在舍入误差)。

要查找此类运算符的文档,请在 R 控制台上输入以下内容:

help("%/%")
英文:

/ does the usual division.

Regarding %/%, the documentation states:

> %% indicates x mod y and %/% indicates integer division. It
is guaranteed that x == (x %% y) + y * ( x %/% y ) (up to
rounding error) unless y == 0 […]

To find the documentation for such operators, enter the following on the R console:

help("%/%")

答案2

得分: 3

这两者都是算术运算符。第一个是除法,第二个是整数除法。请参考此链接:https://www.statmethods.net/management/operators.html

10/3
[1] 3.333333
10%/%3
[1] 3

另外,还有取模运算符 (x %% y)

10%%3
[1] 1

这就是我知道的关于除法运算符的全部信息 ‘/’ 运算符和 ‘%/%’ 运算符在R编程语言中有什么区别?

英文:

Both are arithmetic operators. The first one is division, the second is integer division. See here: https://www.statmethods.net/management/operators.html

> 10/3
[1] 3.333333
> 10%/%3
[1] 3

In addition, there is also modulus division (x %% y)

> 10%%3
[1] 1

That's all I know about division operators ‘/’ 运算符和 ‘%/%’ 运算符在R编程语言中有什么区别?

huangapple
  • 本文由 发表于 2020年1月3日 18:31:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576969.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定