# NOT RUN {
# To convert data frame to tidy data (long) format, run:
library(dplyr)
library(tidyr)
library(stringr)
airline_safety_tidy <- airline_safety %>%
pivot_longer(-c(airline, incl_reg_subsidiaries, avail_seat_km_per_week),
names_to = "type", values_to = "count") %>%
mutate(
period = str_sub(type, start=-5),
period = str_replace_all(period, "_", "-"),
type = str_sub(type, end=-7)
)
# }
Run the code above in your browser using DataLab