The question arose after the quiz today:

Is it possible to write the heightReact() function wthout using an if .. else or the ifelse() function?

The answer is actually Yes, but you have to be sneaky. Here is one if-less way:

heightReact <- function(n = 70) {
  reaction <- c("short", "tall")
  reaction[as.numeric(n > 72) + 1]
}

Does it work? Let’s see:

heightReact()
## [1] "short"
heightReact(75)
## [1] "tall"
heightReact(65)
## [1] "short"

Yep, it works. You might enjoy figuring out how!