Forked from trinker/crosstabs with tidyr and dplyr
Created
September 26, 2018 15:34
-
-
Save sbalci/c88e7a42c0d086336186abb9245e755b to your computer and use it in GitHub Desktop.
crosstabs with tidyr and dplyr
This file contains hidden or 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
if (!require("pacman")) install.packages("pacman") | |
pacman::p_load(dplyr, tidyr, wakefield) | |
set.seed(10) | |
dat <- r_data_frame(n = 10000, | |
race, | |
age, | |
sex | |
) | |
dat %>% | |
count(Race, Age, Sex) %>% | |
spread(Age, n, fill =0) | |
dat %>% | |
count(Race, Age, Sex) %>% | |
spread(Race, n, fill =0) | |
dat %>% | |
count(Race, Age, Sex) %>% | |
unite(Race_Sex, Race, Sex) %>% | |
spread(Race_Sex, n, fill =0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment