Challenge - 5 Problems
R Programming Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
Output of a simple R print statement
What is the output of this R code?
print("Hello, R!")R Programming
print("Hello, R!")
Attempts:
2 left
💡 Hint
Remember that print() in R shows the index and quotes for strings.
✗ Incorrect
In R, print() outputs the index [1] and the string with quotes.
❓ Predict Output
intermediate1:30remaining
Value of a variable after assignment
What is the value of variable
x after running this code?x <- 5 + 3 * 2 x
R Programming
x <- 5 + 3 * 2 x
Attempts:
2 left
💡 Hint
Remember the order of operations: multiplication before addition.
✗ Incorrect
3 * 2 = 6, then 5 + 6 = 11, so x is 11.
❓ Predict Output
advanced2:00remaining
Output of a vector creation and print
What is the output of this R code?
v <- c(1, 2, 3, 4) print(v[2:4])
R Programming
v <- c(1, 2, 3, 4) print(v[2:4])
Attempts:
2 left
💡 Hint
Indexing in R starts at 1 and 2:4 means elements 2 to 4.
✗ Incorrect
v[2:4] selects elements 2, 3, and 4 which are 2, 3, and 4.
❓ Predict Output
advanced2:00remaining
Output of a conditional statement
What is the output of this R code?
num <- 7
if (num %% 2 == 0) {
print("Even")
} else {
print("Odd")
}R Programming
num <- 7 if (num %% 2 == 0) { print("Even") } else { print("Odd") }
Attempts:
2 left
💡 Hint
Check if 7 is divisible by 2 with no remainder.
✗ Incorrect
7 %% 2 is 1, so condition is false, else prints "Odd".
❓ Predict Output
expert3:00remaining
Output of a function with recursion
What is the output of this R code?
factorial <- function(n) {
if (n == 0) return(1)
else return(n * factorial(n - 1))
}
factorial(4)R Programming
factorial <- function(n) {
if (n == 0) return(1)
else return(n * factorial(n - 1))
}
factorial(4)Attempts:
2 left
💡 Hint
Factorial of 4 is 4 * 3 * 2 * 1.
✗ Incorrect
factorial(4) = 4 * factorial(3) = 4 * 6 = 24.