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