The if else statement
An if-else statement is a great tool for the developer trying to return an output based on a condition. In R, the syntax is:
if (condition) {
Expr1
} else {
Expr2
}
The else if statement
We can further customize the control level with the else if statement. With elif, you can add as many conditions as we want. The syntax is:
if (condition1) {
expr1
} else if (condition2) {
expr2
} else if (condition3) {
expr3
} else {
expr4
}