Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.