7.7 Exercise

We will work with a modified version of the storms data set: positions and attributes of 198 tropical storms, measured every 6 hours.

  1. Download and read in this file (using a tidyverse function!):
  • store the dataset into object mystorms, and then tidy it!
  1. What storm has the highest median wind speed?
  2. Calculate how many storms happen each year. You might need to separate a column… And check how the distinct function can help you!
  • What are the years with the maximum number of storms?
Answer
# 1. download, read in, tidy
mystorms <- read_csv("https://public-docs.crg.es/biocore/projects/training/R_tidyverse_2021/modified_storms.csv") %>%
            separate(col=wind_and_pressure, into=c("wind", "pressure"), sep="-", convert=TRUE) 

# 2. What storm has the highest median wind speed?
mystorms %>% group_by(name) %>%
            summarise(median_wind = median(wind)) %>%
            slice_max(order_by=median_wind)
      
# 3. Calculate how many storms happen each year: 
mystorms %>%  separate(date, into=c("year", "month", "day"), sep="-") %>%
          distinct(name, year) %>%
          group_by(year) %>%
          summarise(storms_per_year=n())
  #  What are the years with the **maximum** number of storms?
mystorms %>%  separate(date, into=c("year", "month", "day"), sep="-") %>%
          distinct(name, year) %>%
          group_by(year) %>%
          summarise(storms_per_year=n()) %>%
          slice_max(order_by=storms_per_year, n=5)