Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save elipousson/0615fc265da4ec80675784aa707e9418 to your computer and use it in GitHub Desktop.
Save elipousson/0615fc265da4ec80675784aa707e9418 to your computer and use it in GitHub Desktop.
A code sample from the in-class live coding practice session for week 3 of the GES 668 Building Spatial Datasets (Fall 2023) course: https://bldgspatialdata.github.io/website/weeks/week_03.html
library(tidyverse)
select(storms, name)
select(storms, !name)
select(storms, -name)
select(storms, name:long)
select(storms, c(name, starts_with("l"), ends_with("diameter")))
select(storms, latitude, longitude)
select(storms, lat, long)
select(
storms,
all_of(c("lat", "latitude", "y", "lon", "long", "longitude", "x"))
)
filter(storms, status == "hurricane")
filter(storms, !is.na(category))
filter(storms, wind %in% c(20, 30, 40, 50, 60, 70))
filter(storms, wind < 15)
filter(storms, wind %in% c(1:14))
storms |>
filter(!is.na(category), category > 3) |>
ggplot() +
geom_point(
aes(long, lat, color = as.factor(category))
) +
scale_color_brewer(type = "seq")
storms |>
filter(
between(hurricane_force_diameter, 110, 125),
between(tropicalstorm_force_diameter, 230, 250)
) |>
View()
storms |>
mutate(
ratio = pressure / wind,
.before = any_of(c("year", "yr"))
)
storms |>
group_by(year, name) |>
mutate(
prior_wind = lag(wind),
wind_change = wind - prior_wind,
.before = everything()
) |>
relocate(
wind,
.before = everything()
) |>
View()
mutate(
storms,
beaufort_desc = case_when(
wind < 1 ~ "Calm",
wind < 4 ~ "Light Air",
wind < 8 ~ "Light Breeze",
wind < 13 ~ "Gentle Breeze",
wind < 19 ~ "Moderate Breeze",
wind < 25 ~ "Fresh Breze",
wind < 32 ~ "Strong Breeze",
wind < 39 ~ "Near Gale",
wind < 47 ~ "Gale",
wind < 55 ~ "Strong Gale",
wind < 64 ~ "Whole Gale",
wind < 75 ~ "Storm Force",
.default = "Hurricane Force"
),
.before = everything()
) |>
View()
storms |>
filter(!is.na(category)) |>
group_by(year) |>
summarise(
avg_month = mean(month),
count = n_distinct(name),
duration = max(month) - min(month),
# min_month = min(month),
# max_month = max(month),
min_wind = min(wind),
max_wind = max(wind)
) |>
ggplot(aes(year, count)) +
geom_col()
storms |>
slice_max(order_by = month)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment