I am a newbie in R and try to find out simple operations. When I run the code below, I get the double results even though I divide the two integer variables.
我是R的新手,试图找出简单的操作。当我运行下面的代码时,即使我将两个整数变量分开,我也得到了双重结果。
p <- 10L
l <- 2L
t <- (p / l)
typeof(t)
Output: [1] "double"
输出:[1]“双”
What is the reason of this? Is it necessary to implement any other thing to get integer value?
这是什么原因?是否有必要实现任何其他东西来获得整数值?
1 个解决方案
#1
2
Integer division in R is done with %/%
R中的整数除法用%/%完成
(p %/% l)
# [1] 5
typeof(p %/% l)
# [1] "integer"
See the ?Arithmetic
help page.
请参阅“算术帮助”页面。
#1
2
Integer division in R is done with %/%
R中的整数除法用%/%完成
(p %/% l)
# [1] 5
typeof(p %/% l)
# [1] "integer"
See the ?Arithmetic
help page.
请参阅“算术帮助”页面。