Skip to content

Instantly share code, notes, and snippets.

@adamhsparks
Last active March 17, 2021 12:07
Show Gist options
  • Save adamhsparks/45efe2589286ed871b0f875a99c756ad to your computer and use it in GitHub Desktop.
Save adamhsparks/45efe2589286ed871b0f875a99c756ad to your computer and use it in GitHub Desktop.
Download and calculate country and year mean values for weather variables using GSODR and dplyr
library("GSODR")
library("tidyr")
library("dplyr")
library("countrycode")
w <- get_GSOD(years = 1929:1931)
w <-
w %>%
group_by(CTRY, YEAR) %>%
summarise(
TEMP = mean(TEMP, na.rm = TRUE),
MAX = mean(MAX, na.rm = TRUE),
MIN = mean(MIN, na.rm = TRUE),
PRCP = mean(PRCP, na.rm = TRUE),
RH = mean(RH, na.rm = TRUE),
WDSP = mean(WDSP, na.rm = TRUE)
) %>%
left_join(codelist, by = c("CTRY" = "fips")) %>% # add country names and codes
select(c(
"CTRY",
"YEAR",
"TEMP",
"MIN",
"PRCP",
"RH",
"WDSP",
"iso3c",
"iso2c",
"country.name.en"
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment