This file contains 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
``` r | |
if(!require("pak")) install.packages("pak") | |
new_packages <- c( | |
"incidence2", | |
"outbreaks", | |
"tidyverse" | |
) | |
pak::pkg_install(new_packages) |
This file contains 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
``` r | |
library(tidyverse) | |
# epiparameter ------------------------------------------------------------ | |
library(epiparameter) | |
# get set of epidist objects | |
epidist_input <- epiparameter::epidist_db( | |
disease = "covid", |
This file contains 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
``` r | |
# packages ---------------------------------------------------------------- | |
library(tidyverse) | |
library(incidence2) | |
# input ------------------------------------------------------------------- | |
onset <- tibble( | |
date = seq(ymd(20200101),ymd(20200104),1), |
This file contains 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
If I need to install python packages | |
```{python} | |
# install packages | |
pip install pandas | |
pip install matplotlib | |
``` | |
I can install python (!!) and the packages in R using `{reticulate}` |
This file contains 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
``` r | |
# from py to R ------------------------------------------------------------ | |
# to convert the a python notebook to Rmd file | |
# with https://pkgs.rstudio.com/rmarkdown/reference/convert_ipynb.html | |
# for one sample ---------------------------------------------------------- | |
set.seed(123) |
This file contains 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
``` r | |
# from dplyr -------------------------------------------------------------- | |
# https://dplyr.tidyverse.org/articles/rowwise.html#creating | |
library(tidyverse) | |
df <- tibble( | |
x = 1:2, | |
y = 3:4, |
This file contains 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
# tidyr::complete() & tidyr::full_seq() ----------------------------------- | |
# Turning implicit missing values into explicit missing values. | |
# Bonus: Filling in gaps in a date range | |
library(tidyr) | |
library(tibble) | |
library(dplyr) | |
# Making up some observations from two weather stations. |
This file contains 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
``` r | |
library(tidyverse) | |
#> Warning: package 'tidyverse' was built under R version 4.2.3 | |
#> Warning: package 'ggplot2' was built under R version 4.2.3 | |
#> Warning: package 'tibble' was built under R version 4.2.3 | |
#> Warning: package 'forcats' was built under R version 4.2.3 | |
# library(datapasta) | |
# tribble_paste() |
This file contains 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
if (!require("pacman")) install.packages("pacman") | |
#> Loading required package: pacman | |
pacman::p_load(tidyverse) | |
# con missing como NA ----------------------------------------------------- | |
f1 <- tibble(variable = c("a", "a", NA, NA, "a", "b", | |
NA, "c", "a", "c", "b")) | |
f1 | |
#> # A tibble: 11 × 1 |
This file contains 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
# https://dplyr.tidyverse.org/articles/rowwise.html | |
``` r | |
library(tidyverse) | |
# how to use across() ------------------------------------------------------- | |
# _ with summary functions ------------------------------------------------ | |
# from cheetsheet | |
# summarise(mtcars, across(everything(), mean)) |
NewerOlder