In R and reporttools: Can I suppress the β€œall” categories of grouped statistics created using the Continuous table?

I am working with the tableContinuous function of the reporttools package in R.

Everything works as expected, and using some example from docs :

 library("reporttools") data(CO2) vars <- CO2[, 4:5] group <- CO2[, "Treatment"] weights <- c(rep(1, 60), rep(0, 10), rep(2, 14)) tableContinuous(vars = vars, weights = weights, subset = c(rep(TRUE, 57), rep(FALSE, 100 - 57)), group = group, prec = 3, print.pval = "kruskal", cap = "Table of continuous variables.", lab = "tab: descr stat") 

I get the table as expected:

enter image description here

Is it possible to remove all lines from output?

+4
source share
1 answer

No, this option is not available in tableContinuous . The lines all are omitted only if for each variable there is only one level, i.e. See if (n.levels == 1) ... at the end of the tableContinuous source.

However, this problem can be solved with regular expressions. I am not an expert in this, so there may be better ways.

 library(reporttools) data(CO2) vars <- CO2[, 4:5] group <- CO2[, "Treatment"] weights <- c(rep(1, 60), rep(0, 10), rep(2, 14)) result <- tableContinuous(vars = vars, weights = weights, subset = c(rep(TRUE, 57), rep(FALSE, 100 - 57)), group = group, prec = 3, print.pval = "kruskal", cap = "Table of continuous variables.", lab = "tab: descr stat") 

Delete all lines completely:

 cat(gsub("\\\\hline\n[^\n]+& all &[^\n]+\n", "", result)) 

Saving p values:

 greg <- gregexpr("p (=|<) [^\n]+", result) regmatches(result, greg) <- list(gsub("(?<=&)[-.\\w ]+", " ", regmatches(result, greg)[[1]], perl = TRUE)) cat(result) 
+2
source

Source: https://habr.com/ru/post/1482986/


All Articles