Challenge - 5 Problems
Code Chunk Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple code chunk
What is the output of this R code chunk?
R Programming
x <- 5 x * 3
Attempts:
2 left
💡 Hint
Remember that * means multiplication in R.
✗ Incorrect
The variable x is assigned the value 5. Multiplying 5 by 3 gives 15, so the output is [1] 15.
❓ Predict Output
intermediate2:00remaining
Output of a code chunk with a function
What is the output of this R code chunk?
R Programming
square <- function(n) {
return(n^2)
}
square(4)Attempts:
2 left
💡 Hint
The function returns the square of the input number.
✗ Incorrect
The function square returns the input number raised to the power of 2. 4 squared is 16.
❓ Predict Output
advanced2:00remaining
Output of a code chunk with vector recycling
What is the output of this R code chunk?
R Programming
v1 <- c(1, 2, 3) v2 <- c(4, 5) v1 + v2
Attempts:
2 left
💡 Hint
R recycles the shorter vector to match the length of the longer vector.
✗ Incorrect
v2 is recycled to c(4,5,4). Adding element-wise: 1+4=5, 2+5=7, 3+4=7.
❓ Predict Output
advanced2:00remaining
Output of a code chunk with a factor variable
What is the output of this R code chunk?
R Programming
f <- factor(c('low', 'medium', 'high', 'medium'), levels = c('low', 'medium', 'high')) levels(f)[2] <- 'mid' f
Attempts:
2 left
💡 Hint
Changing the second level name changes the factor labels accordingly.
✗ Incorrect
The second level 'medium' is renamed to 'mid'. The factor values update to reflect this change.
❓ Predict Output
expert3:00remaining
Output of a code chunk with nested functions and environment
What is the output of this R code chunk?
R Programming
outer <- function(x) {
inner <- function(y) {
x + y
}
inner(10)
}
outer(5)Attempts:
2 left
💡 Hint
The inner function uses x from the outer function's environment.
✗ Incorrect
The outer function defines x=5 and calls inner(10). Inner adds x + y = 5 + 10 = 15.