Rainbow Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Creating functions
If statements
15. if statements inside functions
Summary

Instruction

Perfect! In the previous exercise, you wrote a function that returns "high", "medium", or "low" based on an input salary value:

salary_category <- function(salary){
  if (0 < salary & salary <= 2500) {
    return("low")
  } else if (2500 < salary & salary <= 4000) {
    return("medium")
  } else {
    return("high")
  }
}

You've written three return statements, but only one of them will get executed, since the conditions are all mutually exclusive.

Exercise

Write the above_average() function that returns TRUE if the first argument is greater than the average of the vector (provided as the second argument) and FALSE otherwise.