class: center, middle, inverse, title-slide # STA199 Lab ### January 25, 2022 --- ## if_else `\(x\)` is a boolean value. What does this mean? <br> -- What do you think the code below does? ```r if(x == TRUE) { print("This above all; to thine own self be true.") } else { print("False face must hide what the false heart doth know.") } ``` --- ## Example Using the recent NYC `flights` dataset from class: Let's categorize flights based on where they departed from. If a flight originated from Laguardia airport (LGA), we'll keep it as "LGA", otherwise we'll label it "Not LGA". To help with this, we'll use an `if_else` statement. ```r flights %>% mutate(new_origin = ifelse(origin == "LGA", "LGA", "Not LGA")) %>% select(origin, new_origin) %>% head(5) ``` ``` ## # A tibble: 5 × 2 ## origin new_origin ## <chr> <chr> ## 1 EWR Not LGA ## 2 LGA LGA ## 3 JFK Not LGA ## 4 JFK Not LGA ## 5 LGA LGA ```