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

example on using a categorical render function in ttt ? #3

Open
smouksassi opened this issue Sep 2, 2024 · 0 comments
Open

example on using a categorical render function in ttt ? #3

smouksassi opened this issue Sep 2, 2024 · 0 comments

Comments

@smouksassi
Copy link

Hi Ben,
I hope this message find you well I was wondering if you have an example on how to use "categorical" render function in ttt.
Sometimes I try to replicate what table1 does in ttt when I need more splits and flexibility. I did not know how to make a render function compatible with ttt as render.categorical.default is not compatible edited it by removing the extra row and now it works
but wanted to hear from the expert !

library(table1)`
library(ttt)
library(ggplot2)

mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$vs <- as.factor(mtcars$vs)
mtcars$am <- as.factor(mtcars$am)

table1(~cyl|eqcut(mtcars$mpg,2,varlabel = "mpg")+vs, data=mtcars,overall = FALSE)

table1(~cyl|eqcut(mtcars$mpg,2,varlabel = "mpg")+ paste(vs,am,sep = "/"), data=mtcars,overall = FALSE)


ttt(data = mtcars,cyl~ 1 | eqcut(mtcars$mpg,2,varlabel= "mpg")+ vs + am,
    render=paste, collapse="<br/>")

ttt(data = mtcars,cyl~  vs + am| eqcut(mtcars$mpg,2,varlabel= "mpg"),
    render=paste, collapse="<br/>")

render.categorical.sm <- function (x, ..., na.is.category = TRUE) 
{
  unlist(c(sapply(
    stats.apply.rounding(stats.default(x, ...),...),
    function(y) with(y, sprintf("%s (%s%%)", FREQ,if (na.is.category) PCT else PCTnoNA)))))
}
ttt(data = mtcars,cyl~  vs + am| eqcut(mtcars$mpg,2,varlabel= "mpg"),
    render=render.categorical.sm, collapse="<br/>",
    expand.along = "rows")
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

1 participant