Skip to content

Instantly share code, notes, and snippets.

@MilesMcBain
Created September 14, 2016 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MilesMcBain/cdd5f8362c85fb8ecd653fc44a0c174f to your computer and use it in GitHub Desktop.
Save MilesMcBain/cdd5f8362c85fb8ecd653fc44a0c174f to your computer and use it in GitHub Desktop.
#Hadley Gapminder Way
nested_iris <-
iris %>%
mutate(Setosa = ifelse(Species == "Setosa", yes=1, no=0) ) %>%
select(-Species) %>%
gather(key="measure", value="value", Sepal.Length:Petal.Width) %>%
nest(Setosa, value)
iris_models <- map(nested_iris$data, ~ glm(data=.,
formula = Setosa ~ value,
family=binomial(link="logit")) )
map(iris_models, glance)
#Miles Invoke Rows Way
iris %>%
mutate(Setosa = ifelse(Species == "Setosa", yes=1, no=0) ) %>%
select(-Species) %>%
gather(key="measure", value="value", Sepal.Length:Petal.Width) %>%
nest(Setosa, value) %>%
invoke_rows(.f=function(measure, data){
glm(data=data,
formula = Setosa ~ value,
family=binomial(link="logit")) %>% glance()
},
.d = .,
.collate="rows")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment