crosstable
crosstable copied to clipboard
implement cbind.crosstable()
left_join()
seems to work but as_flextable()
needs to look better.
Check that cols
is the same on both flextables.
add a syntax in by
maybe? It would be confusing with by=c(vs, am)
, maybe by=list(vs, am)
? or a custom wrapper?
library(tidyverse)
library(crosstable)
ct1 = crosstable(mtcars, cyl, by=vs)
ct2 = crosstable(mtcars, cyl, by=am)
ct = left_join(ct1, ct2, by=c(".id", "label", "variable"),
suffix=c("_vs", "_am"))
ct
#> # A tibble: 3 × 7
#> .id label variable `0_vs` `1_vs` `0_am` `1_am`
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 cyl cyl 4 1 (9.09%) 10 (90.91%) 3 (27.27%) 8 (72.73%)
#> 2 cyl cyl 6 3 (42.86%) 4 (57.14%) 4 (57.14%) 3 (42.86%)
#> 3 cyl cyl 8 14 (100.00%) 0 (0%) 12 (85.71%) 2 (14.29%)
as_flextable(ct)
Created on 2022-06-16 by the reprex package (v2.0.1)
Source: https://stackoverflow.com/questions/70841416/creating-crosstable-with-multiple-variables-summarized-by-row-categories/72641518#72641518