Last active
September 25, 2023 19:55
-
-
Save lcolladotor/680d610464e3a4cbd7dcf12c2203ed7e to your computer and use it in GitHub Desktop.
Notes from my session with Natalie
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("dplyr") | |
library("sessioninfo") | |
tuesdata <- tidytuesdayR::tt_load("2020-01-07") | |
rainfall <- tuesdata$rainfall | |
rainfall_filtered <- rainfall %>% | |
filter(city_name == "Cuernavaca") | |
rainfall_filtered | |
nrow(rainfall_filtered) | |
check_city_exists <- function(city = "Cuernavaca") { | |
rainfall_filtered <- rainfall %>% | |
filter(city_name == city) | |
if (nrow(rainfall_filtered) == 0) { | |
stop("The 'city' ", city, " is absent from rainfall.", call. = FALSE) | |
} | |
return(rainfall_filtered) | |
} | |
check_city_exists() | |
check_city_exists("Perth") | |
check_city_year_exists <- | |
function(city = "Cuernavaca", | |
year_of_interest = 1967) { | |
rainfall_filtered <- rainfall %>% | |
filter(city_name == city & year == year_of_interest) | |
if (nrow(rainfall_filtered) == 0) { | |
stop( | |
"The 'city' ", | |
city, | |
" with 'year' ", | |
year_of_interest, | |
" is absent from rainfall.", | |
call. = FALSE | |
) | |
} | |
return(rainfall_filtered) | |
} | |
check_city_year_exists() | |
check_city_year_exists("Perth", year_of_interest = 18) | |
check_city_year_exists("Perth") | |
library("ggplot2") | |
check_city_year_exists("Perth") %>% | |
tidyr::drop_na(rainfall) %>% | |
ggplot(aes(log(rainfall))) + | |
geom_histogram() | |
check_city_year_exists("Perth") %>% | |
tidyr::drop_na(rainfall) %>% | |
ggplot(aes(rainfall)) + | |
geom_histogram() | |
check_city_year_exists("Perth") %>% | |
tidyr::drop_na(rainfall) %>% | |
ggplot(aes(rainfall + 1e-10)) + | |
geom_histogram() + | |
scale_x_log10() | |
check_city_year_exists("Perth") %>% | |
tidyr::drop_na(rainfall) %>% | |
ggplot(aes(log(rainfall + 1e-10))) + | |
geom_histogram() + | |
xlab("log(rainfall)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment