0
0
R Programmingprogramming~20 mins

First R program in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
R Programming Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
Output of a simple R print statement
What is the output of this R code?
print("Hello, R!")
R Programming
print("Hello, R!")
A"Hello, R!"
BHello, R!
C[1] Hello, R!
D[1] "Hello, R!"
Attempts:
2 left
💡 Hint
Remember that print() in R shows the index and quotes for strings.
Predict Output
intermediate
1: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
A11
B16
C10
DError
Attempts:
2 left
💡 Hint
Remember the order of operations: multiplication before addition.
Predict Output
advanced
2: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])
A[2] 2 3 4
B[1] 2 3 4
CError: subscript out of bounds
D[1] 1 2 3
Attempts:
2 left
💡 Hint
Indexing in R starts at 1 and 2:4 means elements 2 to 4.
Predict Output
advanced
2: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")
}
A7
B[1] "Even"
C[1] "Odd"
DError: object 'num' not found
Attempts:
2 left
💡 Hint
Check if 7 is divisible by 2 with no remainder.
Predict Output
expert
3: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)
A24
B10
CError: recursive call limit reached
D1
Attempts:
2 left
💡 Hint
Factorial of 4 is 4 * 3 * 2 * 1.