Challenge - 5 Problems
Integer Type Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of integer division in R?
Consider the following R code:
What will be printed?
x <- 7L result <- x %/% 2 print(result)
What will be printed?
R Programming
x <- 7L result <- x %/% 2 print(result)
Attempts:
2 left
💡 Hint
The operator %/% performs integer division, which discards the remainder.
✗ Incorrect
In R, %/% divides two numbers and returns the integer quotient by discarding any remainder. So 7 %/% 2 equals 3.
❓ Predict Output
intermediate2:00remaining
What is the type of an integer literal in R?
What is the output of this code?
typeof(5L)
R Programming
typeof(5L)Attempts:
2 left
💡 Hint
The suffix L forces the number to be an integer type.
✗ Incorrect
In R, adding L after a number makes it an integer literal. typeof(5L) returns "integer".
🔧 Debug
advanced2:00remaining
Why does this integer overflow happen?
Examine this R code:
What is the output and why?
large_int <- 2147483647L result <- large_int + 1L print(result)
What is the output and why?
R Programming
large_int <- 2147483647L result <- large_int + 1L print(result)
Attempts:
2 left
💡 Hint
R integers are 32-bit signed and wrap around on overflow.
✗ Incorrect
The maximum 32-bit signed integer is 2147483647. Adding 1 causes wrap-around to -2147483648 due to overflow.
🧠 Conceptual
advanced2:00remaining
What happens when mixing integer and double in arithmetic?
What is the type of the result of this R expression?
typeof(5L + 2.0)
R Programming
typeof(5L + 2.0)
Attempts:
2 left
💡 Hint
R converts integers to doubles when mixed in arithmetic.
✗ Incorrect
When an integer and a double are combined in arithmetic, R converts the integer to double. So the result is double type.
❓ Predict Output
expert2:00remaining
How many elements are in this integer vector after coercion?
What is the length of the vector created by this code?
vec <- c(1L, 2.5, 3L, TRUE, "4") length(vec)
R Programming
vec <- c(1L, 2.5, 3L, TRUE, "4") length(vec)
Attempts:
2 left
💡 Hint
All elements are coerced to a common type in c().
✗ Incorrect
The vector has 5 elements. R coerces all to character because of the string "4". length() returns 5.