Created
December 18, 2015 22:32
-
-
Save trinker/184cc9f0624bad85de10 to your computer and use it in GitHub Desktop.
crosstabs with tidyr and dplyr
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
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