Closed Qiyun506 closed 7 months ago
Sorry for the delay in addressing your question. Although it could possibly be done somehow, table1
might not be the ideal package for this kind of table. If you want to try my other package ttt, you could do something like this:
library(ttt)
options(ttt.theme="booktabs")
lev <- c("Normal or Low", "Abnormal high, NCS", "Abnormal high, CS")
dat <- data.frame(pre=factor(c(rep(lev[1], 7), lev[2]), levels=lev))
dat$post <- dat$pre
shift_table <- function(pre, post, label) {
tab <- table(pre, post)
a <- attributes(tab)
tab <- sprintf("%s (%s%%)", tab, 100*prop.table(tab))
tab <- gsub(" (0%)", "", tab, fixed=T)
attributes(tab) <- a
tab <- as.data.frame(tab)
tab <- rbind(
data.frame(
pre=factor(levels(pre), levels=levels(pre)),
post=factor(" "), Freq=" "),
tab)
tab$label <- label
label(tab$label) <- "Parameter (unit)"
label(tab$post) <- "Postbaseline"
ttt(Freq ~ label + post | pre, data=tab, lab="Baseline")
}
shift_table(dat$pre, dat$post,
label="Alanine<br/>Aminotransferase<br/>(ALT/SGPT) (U/L)")
Hi, When I use the table1 pacakge to generate a shift table, to see how a var change after certain experiement. Subjects initial are normal, low abnormal, and abnormal, but for some sample, their initial status are all normal, as a result when use your table, the thing showed in table is not 0 but nothing. like this:
Mine:
Expected:
![wish](https://github.com/benjaminrich/table1/assets/83425380/d6d069c0-1918-4c14-b2be-89088afd43e0)
Can anyone help me with that?