#How to calculate row-wise percentages in a using the arsenal package
#The code below produces col-wise percentages, but i would like to produce row-wise percentages.
library(arsenal)
library(forcats)
df <- data.frame(arm = sample(c("Int","Contr"),size=10, replace = T),
sex = sample(c("Male", "Female"),size=10, replace = T),
agegp = sample(c("<15","15-49",">50"),size=10, replace = T))
tab1 <- tableby(arm ~ sex + agegp, data=df)
summary(tab1, text=TRUE)
#>
#>
#> | | Contr (N=7) | Int (N=3) | Total (N=10) | p value|
#> |:---------|:-----------:|:----------:|:------------:|-------:|
#> |sex | | | | 1.000|
#> |- Female | 4 (57.1%) | 1 (33.3%) | 5 (50.0%) | |
#> |- Male | 3 (42.9%) | 2 (66.7%) | 5 (50.0%) | |
#> |agegp | | | | 0.040|
#> |- <15 | 1 (14.3%) | 3 (100.0%) | 4 (40.0%) | |
#> |- >50 | 3 (42.9%) | 0 (0.0%) | 3 (30.0%) | |
#> |- 15-49 | 3 (42.9%) | 0 (0.0%) | 3 (30.0%) | |
Created on 2018-10-05 by the reprex package (v0.2.1)