Created
October 14, 2023 21:34
-
-
Save elipousson/6561dd7c39bec526f2dc1b92c40a8d8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(sf) | |
c("A", "B", "C") | |
"ABC" | |
str_flatten(c("A", "B", "C")) | |
us_states |> | |
group_by(DIVISION) |> | |
summarise( | |
names = str_flatten_comma(NAME, | |
collapse = ", ", | |
last = " and ") | |
) | |
# Selecting states | |
us_states[us_states$NAME == "Maryland", ] | |
us_states[us_states$NAME == "Virginia", ] | |
us_states[us_states$NAME == "California", ] | |
# Deselecting states | |
us_states[us_states$NAME %in% c("Virginia", "California"), ] | |
us_states[us_states$NAME %in% c("California"), ] | |
us_states |> | |
filter(NAME == "Maryland") | |
us_states_out <- st_write(us_states, "us_states.geojson") | |
avg_scalek_round <- function(x) { | |
round(mean(x) / 1000, digits = 2) | |
} | |
scalek_round <- function(x) { | |
round(x / 1000, digits = 2) | |
} | |
us_states |> | |
mutate( | |
ALAND_K = scalek_round(ALAND), | |
AWATER_K = scalek_round(AWATER) | |
) | |
storms |> | |
group_by(category) |> | |
summarise( | |
avg_wind = avg_scalek_round(wind) | |
) | |
avg_scalek_round <- function(x) { | |
round(mean(x) / 1000, digits = 2) | |
} | |
scale_round <- function(x, y) { | |
round(x / y, digits = 2) | |
} | |
avg_scale_round <- function(x, scale = 1000, na.rm = TRUE) { | |
round(mean(x, na.rm = na.rm) / scale, digits = 2) | |
} | |
us_states |> | |
mutate( | |
ALAND_K = round(ALAND / 1000, digits = 2), | |
AWATER_K = round(AWATER / 1000, digits = 2) | |
) | |
storms |> | |
group_by(category) |> | |
summarise( | |
avg_wind = avg_scale_round(wind) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment