In [ ]:
library(nycflights13)
library(tidyverse)
Use them similarly:
>, >=, <, <=, !=, ==near(sqrt(2)^2, 2)&, |, !x %in% yNA is NA.TRUE, excludes both NA and FALSEstarts_with and matches, see ?select_helpersmutate() can use the variable just createdtransmute() only keeps the new variablesdelays <- flights %>%
group_by(dest) %>%
summarise(
count = n(),
dist = mean(distance, na.rm = TRUE),
delay = mean(arr_delay, na.rm = TRUE)
) %>%
filter(count > 20, dest != "HNL")
In [ ]:
flights
In [ ]:
(jan1 <- filter(flights, month == 1, day == 1))
In [ ]:
filter(flights, arr_delay <= 120 & dep_delay <= 120)
In [ ]:
df <- tibble(x = c(1, NA, 3))
filter(df, x > 1)
In [ ]:
filter(df, is.na(x) | x > 1)
In [ ]:
# 1.1 Had an arrival delay of two or more hours
filter(flights, arr_delay >= 2)
In [ ]:
# Flew to Houston (IAH or HOU)
filter(flights, dest %in% c("IAH", "HOU"))
In [ ]:
# Were operated by United, American, or Delta
filter(flights, carrier %in% c("UA", "AA", "DL"))
In [ ]:
# Departed in summer (July, August, and September)
filter(flights, month %in% c(7, 8, 9))
In [ ]:
filter(flights, is.na(dep_time))
In [ ]:
filter(flights, dep_delay >= 60 & arr_delay <= 30)
In [ ]:
filter(flights, dep_time >= 0 & dep_time <= 600)