Skip to content

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

@smouksassi

Description

@smouksassi

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")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions