Subsetting vectors

I.e. keep only a subset of a vector, drop the rest, based on some condition.

  • This is base R!
  • Put a logical vector in the brackets (obtained by one of the previous techniques; often comparison)

E.g.:

condition <- flights$arr_delay > 0
flights$arr_delay[condition]
flights$dep_time[condition]
# or just:
flights$dep_time[flights$arr_delay > 0]