Exercise

ifelse()

A powerful function to know about is ifelse(). It creates an if statement in 1 line of code, and more than that, it works on entire vectors!

Suppose you have a vector of stock prices. What if you want to return "Buy!" each time apple > 110, and "Do nothing!", otherwise? A simple if statement would not be enough to solve this problem. However, with ifelse() you can do: