R If Else
if runs code when a condition is TRUE. Use else if and else for more branches. ifelse() works on whole vectors.
Example
score <- 72
if (score >= 85) { print("Distinction") } else if (score >= 70) { print("Pass") } else { print("Retake") }
print(ifelse(c(40, 80) >= 50, "pass", "fail"))Exercise
Vector friendly if.
(x > 1, "a", "b")Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.