Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ``` r
- library(tidyverse)
- gss_clean <- gss_cat %>%
- filter(race != "Other", marital != "No answer") %>%
- mutate(relig = recode(relig, Protestant = "Protestant", .default = "Not Protestant"),
- marital = recode(marital, Married = "Married", .default = "Not married"),
- race = fct_drop(race))
- gss_all_3 <- gss_clean %>%
- group_by(marital, race, relig) %>%
- nest()
- gss_race_marriage <- gss_clean %>%
- group_by(marital, race) %>%
- nest()
- gss_marriage <- gss_clean %>%
- group_by(marital) %>%
- nest()
- bind_rows(gss_all_3, gss_race_marriage, gss_marriage) %>%
- ungroup() %>%
- arrange(marital, race, relig) %>%
- mutate(summary = data %>% map(~ summarize(., avg_age = mean(age, na.rm = TRUE),
- sd_age = sd(age, na.rm = TRUE),
- N = n()))) %>%
- unnest(summary)
- #> # A tibble: 14 x 7
- #> marital race relig data avg_age sd_age N
- #> <fct> <fct> <fct> <list> <dbl> <dbl> <int>
- #> 1 Not married Black Not Protestant <tibble [672 × 6… 38.6 15.5 14
- #> 2 Not married Black Protestant <tibble [1,586 ×… 44.8 17.1 14
- #> 3 Not married Black <NA> <tibble [2,258 ×… 42.9 16.9 14
- #> 4 Not married White Not Protestant <tibble [4,389 ×… 44.4 18.7 14
- #> 5 Not married White Protestant <tibble [3,677 ×… 51.7 19.8 14
- #> 6 Not married White <NA> <tibble [8,066 ×… 47.7 19.5 14
- #> 7 Not married <NA> <NA> <tibble [10,324 … 46.7 19.1 14
- #> 8 Married Black Not Protestant <tibble [185 × 6… 42.8 11.6 14
- #> 9 Married Black Protestant <tibble [684 × 6… 47.4 13.7 14
- #> 10 Married Black <NA> <tibble [869 × 7… 46.4 13.4 14
- #> 11 Married White Not Protestant <tibble [3,810 ×… 47.8 14.6 14
- #> 12 Married White Protestant <tibble [4,506 ×… 51.3 15.6 14
- #> 13 Married White <NA> <tibble [8,316 ×… 49.7 15.2 14
- #> 14 Married <NA> <NA> <tibble [9,185 ×… 49.4 15.1 14
- ```
Add Comment
Please, Sign In to add comment