Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement cbind.crosstable() #15

Open
DanChaltiel opened this issue Jun 16, 2022 · 0 comments
Open

implement cbind.crosstable() #15

DanChaltiel opened this issue Jun 16, 2022 · 0 comments
Labels
enhancement New feature or request questionning not sure we should do it

Comments

@DanChaltiel
Copy link
Owner

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)

crosstable

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

@DanChaltiel DanChaltiel added the enhancement New feature or request label Jun 16, 2022
@DanChaltiel DanChaltiel added the questionning not sure we should do it label Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request questionning not sure we should do it
Projects
None yet
Development

No branches or pull requests

1 participant