Reputation:
I'm 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 a table as expected:
Is it possible to remove the all
lines from the output?
Upvotes: 4
Views: 547
Reputation: 48241
No, such an option is not available in tableContinuous
. The all
lines are omitted only in case if there is only one level per variable, i.e. see if (n.levels == 1) ...
at the end of the source of tableContinuous
.
However, this problem can be solved using regular expressions. I am not an expert in it so there might 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")
Completely removing all
lines:
cat(gsub("\\\\hline\n[^\n]+& all &[^\n]+\n", "", result))
Keeping p-values:
greg <- gregexpr("p (=|<) [^\n]+", result)
regmatches(result, greg) <- list(gsub("(?<=&)[-.\\w ]+", " ",
regmatches(result, greg)[[1]], perl = TRUE))
cat(result)
Upvotes: 2