Data Manipulation and Visualization with R and the nycflights13 Dataset
Classified in Computers
Written on in English with a size of 3.64 KB
library(nycflights13)
library(tidyverse)
Data Manipulation with dplyr
Ordering Rows with arrange()
arrange(flights, year, month, day)
arrange(flights, desc(arr_delay))
Handling NAs
df <- tibble(x = c(5, 2, NA))
arrange(df, x)
arrange(df, desc(x))
Selecting Columns with select()
select(flights, year, month, day)
select(flights, year:day)
select(flights, -(year:day))
rename(flights, mes = month)
select(flights, time_hour, air_time, everything())
Creating New Variables with mutate()
flights_sml <- select(flights, year:day, ends_with("delay"), distance, air_time)
mutate(flights_sml, gain = arr_delay - dep_delay, speed = distance / air_time * 60)
Creating Functions with Vector Arguments
transmute(flights, dep_time, hour = dep_time %/% 100, minute = dep_time %