I'm working with some survey data and I want to summarize responses from everyone, and responses from members in a single table.
The best way I can think of to translate this to Starwars is that I want to know how many characters total have any one eye color, and how many female characters have that eye color. For simplicity, I limited the population to blue and brown eyes.
I can run to separate queries, one to show just the females:
starwars %>%
filter(eye_color %in% c("brown","blue")) %>%
count(eye_color, gender) %>%
filter(gender == "female") %>%
mutate(percent = n / sum(n) * 100,
percent = sprintf("%.0f%%", percent))
And one to show all characters regardless of gender:
starwars %>%
filter(eye_color %in% c("brown","blue")) %>%
count(eye_color) %>%
mutate(percent = n / sum(n) * 100,
percent = sprintf("%.0f%%", percent))
But I'd like to spit these out as a single table. Is there a better approach to that than just pasting the two resulting tibbles together?