Skip to content

Instantly share code, notes, and snippets.

@joebrew
Created September 8, 2017 13:06
Show Gist options
  • Save joebrew/9e7b9f7bb24619832e88d41715a1213e to your computer and use it in GitHub Desktop.
Save joebrew/9e7b9f7bb24619832e88d41715a1213e to your computer and use it in GitHub Desktop.
Process hurricane data
# Process hurricanes data
hurricanes <-
hurricanes %>%
mutate(year = Season) %>%
# Keep only those since 1917
filter(year >= 1917) %>%
mutate(date_time = ISO_time,
lon = Longitude,
lat = Latitude,
id = Serial_Num,
wind = `Wind(WMO)`,
pressure = `Pres(WMO) Percentile`) %>%
arrange(date_time) %>%
# Keep out those which cross the longitudinal start-over
group_by(id) %>%
mutate(cross_over = any(lon < -100) & any(lon > 100)) %>%
ungroup %>%
filter(!cross_over) %>%
# Keep only those in the Atlantic basin
group_by(id) %>%
filter(any(lon >-90) & any(lon < -10),
any(lat > 10) & (any(lat < 40))) %>%
# Get max wind
mutate(max_wind = max(wind)) %>%
ungroup %>%
# Make ids simple
mutate(id = as.numeric(factor(id)))
# Get an index
hurricanes$index <- 1:nrow(hurricanes)
hurricanes <- hurricanes %>%
group_by(id) %>%
mutate(max_index = max(index)) %>%
ungroup
# Define ids of storms
ids <- sort(unique(hurricanes$id))
years <- sort(unique(hurricanes$year))
max_indices <- sort(unique(hurricanes$max_index))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment