I am using the table1 package and the code below to create a table with region-specific descriptive statistics measures for three variables (i.e. ITE_tech, tech and IMR_tech) that lie in the closed unit interval.
library(table1)
table1::label(results19$ITE_tech) <- "TE"
table1::label(results19$tech) <- "TE_k"
table1::label(results19$IMR_tech) <- "MTR"
table1::table1(~ITE_tech + tech + IMR_tech | REGION, data = results19)
How can I add to the resulting table another row showing the number of times each of the prementioned variables takes the value of 1? I was trying to do this using the code below but this code applies the sum function to only the first variable and excludes the default descriptive statistics measures (i.e. mean, sd, min, max) from the final table.
render.continuous.custom <- function(x, ...) {
attr(x, "label") <- NULL
c(
"",
"Eff. Obs." = sum(results19$tech==1)
)
}
table1::table1(~ITE_tech + tech + IMR_tech | REGION, data = results19, render.continuous = render.continuous.custom)
Thank you in advance for your help.
Here is how you can define the render function:
(Note: a reproducible example would be helpful)