# ============================================================
# Logical Conditions & if/else
# R Foundations — Rverse Analytics
# https://rverseanalytics.com/learn/logical-conditions
# ============================================================

# Comparisons return TRUE or FALSE
5 > 3
5 == 5
"a" != "b"
c(1, 5, 9) >= 5
# Combine tests: & (and), | (or), ! (not), %in%
x <- 7
x > 0 & x < 10
x < 0 | x > 5
5 %in% c(1, 3, 5, 7)
# if / else runs different code for one condition
temp <- 28
if (temp > 25) {
  print("warm")
} else {
  print("cool")
}
# ifelse() applies the test to a whole vector at once
temps <- c(18, 24, 31, 27)
ifelse(temps > 25, "warm", "cool")
