Created
September 14, 2016 14:01
-
-
Save MilesMcBain/cdd5f8362c85fb8ecd653fc44a0c174f to your computer and use it in GitHub Desktop.
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
#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