Onur Degerli
Onur Degerli

Reputation: 219

Unexpected double data type when division of two integer in R

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.

p <- 10L
l <- 2L
t <- (p / l)
typeof(t)

Output: [1] "double"

What is the reason of this? Is it necessary to implement any other thing to get integer value?

Upvotes: 0

Views: 314

Answers (1)

MrFlick
MrFlick

Reputation: 206411

Integer division in R is done with %/%

(p %/% l)
# [1] 5
typeof(p %/% l)
# [1] "integer"

See the ?Arithmetic help page.

Upvotes: 2

Related Questions