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

Don't display N=X per category in the header #99

Open
stefanie-hennig opened this issue Mar 7, 2023 · 2 comments
Open

Don't display N=X per category in the header #99

stefanie-hennig opened this issue Mar 7, 2023 · 2 comments

Comments

@stefanie-hennig
Copy link

stefanie-hennig commented Mar 7, 2023

Hi,
Is there a way to not to display the number of data points contributing to the summary for a category using Table1?

Capture

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
@benjaminrich
Copy link
Owner

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.

@stefanie-hennig
Copy link
Author

Thanks so much for the quick response. It's one of the best packages! I am using it every day. Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants