Chapter 6 if else statement

The if statement only performs an operation if a condition is met. However, one may not only be interested in specifying the expression that must be done when the required condition is TRUE, but also the expression that must be performed when the condition is FALSE.

To achieve this, we can use the if() {} else {} statement and ifelse() function.

if(condition) {
  expression 1
} else {
  expression 2
}
ifelse(condition, 
       expression 1, 
       expression 2
)