Skip to content

Instantly share code, notes, and snippets.

@pachadotdev
Last active February 20, 2019 12:55
Show Gist options
  • Save pachadotdev/5b68d80f1454589eb0d89f7079b36867 to your computer and use it in GitHub Desktop.
Save pachadotdev/5b68d80f1454589eb0d89f7079b36867 to your computer and use it in GitHub Desktop.
trying to reproduce esperanza_de_vida error in R4DS es
if(!require("pacman")) { install.packages("pacman") }
devtools::install_github("pachamaltese/datos")
pacman::p_load(purrr, dplyr, tidyr, datos)
# I need to know what's going on with this "selective" error
sessionInfo()
# inspect datos::paises (countries)
paises
# group paises (countries) by pais (country)
por_pais <- paises %>%
group_by(pais, continente) %>%
nest()
por_pais
por_pais$data[[1]]
# function to obtain one regression per country
modelo_pais <- function(df) {
lm(esperanza_de_vida ~ anio, data = df)
}
# apply regression function to each country
modelos <- map(por_pais$data, modelo_pais)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment