Skip to content

Instantly share code, notes, and snippets.

View avallecam's full-sized avatar
🎯
Focusing

Andree Valle Campos avallecam

🎯
Focusing
View GitHub Profile
@avallecam
avallecam / casos_a_incidencia.R
Last active July 11, 2024 22:58
Usar {incidence2} y {dplyr} para adaptar datos de casos con {EpiNow2} y {cfr}
``` r
if(!require("pak")) install.packages("pak")
new_packages <- c(
"incidence2",
"outbreaks",
"tidyverse"
)
pak::pkg_install(new_packages)
@avallecam
avallecam / epiverse-list_columns.R
Last active May 31, 2024 14:04
functions from {epiparameter} and {epidemics} get tibble-friendly ouputs with list columns from nested data or multiple iterations made internally
``` r
library(tidyverse)
# epiparameter ------------------------------------------------------------
library(epiparameter)
# get set of epidist objects
epidist_input <- epiparameter::epidist_db(
disease = "covid",
@avallecam
avallecam / delays_cfr.R
Last active April 16, 2024 17:56
reporting delays bias CFR
``` r
# packages ----------------------------------------------------------------
library(tidyverse)
library(incidence2)
# input -------------------------------------------------------------------
onset <- tibble(
date = seq(ymd(20200101),ymd(20200104),1),
@avallecam
avallecam / python.Rmd
Last active February 9, 2024 20:10
quick start to use python within R
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}`
@avallecam
avallecam / sampling-distribution-rowwise.R
Last active November 13, 2023 18:32
calculate the sampling distribution as demo for central limit theorem
``` 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)
@avallecam
avallecam / rowwise-examples.R
Last active October 4, 2023 19:33
collect some examples of rowwise relevant (?) data
``` r
# from dplyr --------------------------------------------------------------
# https://dplyr.tidyverse.org/articles/rowwise.html#creating
library(tidyverse)
df <- tibble(
x = 1:2,
y = 3:4,
@avallecam
avallecam / complete.r
Created July 28, 2023 17:24 — forked from deanmarchiori/complete.r
Turning implicit missing values into explicit missing values.
# 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.
@avallecam
avallecam / confidence_intervals.r
Created July 3, 2023 09:38
get confidence intervals from numerator and denominator
``` 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()
@avallecam
avallecam / missing_with_factors.R
Created January 24, 2023 13:52
handle missing observations for factor variables
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
@avallecam
avallecam / how_to_across_dplyr.R
Last active April 15, 2023 19:19
Use across() and c_across() {dplyr} functions!
# https://dplyr.tidyverse.org/articles/rowwise.html
``` r
library(tidyverse)
# how to use across() -------------------------------------------------------
# _ with summary functions ------------------------------------------------
# from cheetsheet
# summarise(mtcars, across(everything(), mean))