Closed d-morrison closed 1 year ago
This is already possible using render.missing
. Here is an example:
require(table1)
require(survival)
set.seed(789)
dat <- subset(survival::pbc, !is.na(trt)) # Exclude subjects not randomized
dat$trt <- factor(dat$trt, levels=1:2, labels=c("D-penicillamine", "Placebo"))
dat$sex <- factor(dat$sex, levels=c("m", "f"), labels=c("Male", "Female"))
# Add some missing values
dat$age[sample(1:nrow(dat), 11)] <- NA
dat$sex[sample(1:nrow(dat), 3)] <- NA
table1(~ age + sex | trt, data=dat, render.missing=c("XYZ"="FREQ (PCT%)"))
Thanks for the reply! I tried that code, and I see that it does use the custom label "XYZ"; however, it doesn't look like the parsing of "FREQ (PCT%)" is working:
#> D-penicillamine Placebo Overall
#> 1 (N=158) (N=154) (N=312)
#> 2 age
#> 3 Mean (SD) 51.2 (11.1) 48.4 (9.99) 49.8 (10.6)
#> 4 Median [Min, Max] 51.2 [26.3, 78.4] 47.6 [30.6, 74.5] 49.6 [26.3, 78.4]
#> 5
#> 6 XYZ FREQ (PCT%) FREQ (PCT%) FREQ (PCT%)
#> 7 sex
#> 8 Male 21 (13.3%) 14 (9.1%) 35 (11.2%)
#> 9 Female 136 (86.1%) 138 (89.6%) 274 (87.8%)
#> 10 X
#> 11 Male.1 21 (13.3%) 14 (9.1%) 35 (11.2%)
#> 12 Female.1 136 (86.1%) 138 (89.6%) 274 (87.8%)
I'll look through the documentation to see if I can figure out the needed format, but would be grateful for hints!
Hmm... that is interesting, because the same code works for me, and produces this:
Installed version 1.4.3 from Github (upgrading from 1.4.2 from CRAN) and it works! Many thanks.
This is an attempt to add an option to replace the label "Missing" for NA counts with a user-supplied string. It isn't quite working yet; I'm still trying to figure out the code structure. I thought I'd start the PR in case you might be willing to guide me.