I have a dataframe with sample classifications:
Seq_ID Family Father Mother Sex Role Type
<chr> <dbl> <chr> <chr> <chr> <chr> <chr>
1 SSC02219 11000. 0 0 Male Father Parent
2 SSC02217 11000. 0 0 Female Mother Parent
3 SSC02254 11000. SSC02219 SSC02217 Male Proband Child
4 SSC02220 11000. SSC02219 SSC02217 Female Sibling Child
5 SSC02184 11001. 0 0 Male Father Parent
6 SSC02181 11001. 0 0 Female Mother Parent
7 SSC02178 11001. SSC02184 SSC02181 Male Proband Child
8 SSC03092 11002. 0 0 Male Father Parent
9 SSC03078 11002. 0 0 Female Mother Parent
10 SSC03070 11002. SSC03092 SSC03078 Female Proband Child
Currently, to go from a to b, I have to do this:
library(tidyverse)
library(janitor)
sample.df %>% tabyl(Role, Sex) %>%
adorn_totals(where=c("row", "col") ) %>%
as.tibble() %>% select(1,4,3,2) %>%
# Part 2
mutate(type=c("parent", "parent", "child", "child", " ")) %>%
inner_join(., group_by(., type) %>%
summarise(total=sum(Total))) %>%
select(5,6,1,2,3,4)
I feel like this is such a workaround for something very simple. Is there a more direct way to do the second part in dplyr?