table1
table1 copied to clipboard
Don't display N=X per category in the header
Hi, Is there a way to not to display the number of data points contributing to the summary for a category using Table1?
Current code is:
rndr <- function(x, name, ...){
f <- function(x){
if (is.na(x) || is.nan(x)) "NC"
else
signif_pad(x, 3)
}
Med = median(x, na.rm = T)
Min = min(x, na.rm = T)
Max = max(x, na.rm = T)
N = length(na.omit(x))
MPI = paste0(f(Med), " [", f(Min), " - ", f(Max), "]", " (",f(N),")")
Tmp <- switch(name,
X = c("Median [Min - Max] (N)" = MPI),
Y = c("Median [Min - Max] (N)" = MPI)
)
parse.abbrev.render.code(c("", Tmp))(x)
}
dat <- read.table(header=T, sep="|", na.strings=".", strip.white=T, text="
ID | TYPE | QQ | X | Y
1 | aa | 1 | 0.13 | .
1 | aa | 2 | . | 1.2
1 | bb | 4 | 1.8 | .
1 | bb | 2 | . | 0.9
2 | aa | 1 | 0.17 | .
2 | aa | 2 | . | 2.1
2 | cc | 1 | 33 | .
2 | cc | 1 | . | 54
")
zebra = "Rtable1-zebra Rtable1-shade Rtable1-times"
tab1 = table1( ~ X + Y | TYPE*QQ,
data = dat,
overall = F, render = rndr,
caption = "", topclass = zebra,
rowlabelhead = "")
tab1
Yes, it's possible. It might not be the most elegant code, but if you pass this argument inside the function call you should get what you want:
render.strat = function(label, ...) sprintf("<span class='stratlabel'>%s</span>", label),
I need to think about a nicer way of integrating this functionality.
Thanks so much for the quick response. It's one of the best packages! I am using it every day. Cheers