tab1 takes lists of continuous and/or categorical variables and returns Median (spread) for continuous variables and N (%) for categorical variables. Produces a table with both an overall column and columns by another variable.

tab1(contvars, catvars, byvar, dat, col = TRUE, spread = "range",
  pval = TRUE, fisher = TRUE)

Arguments

contvars

is a list of the continuous variables you want in the rows e.g. list('Age'). Can be NULL.

catvars

is a list of the categorical variables you want in the rows e.g. list('Gender','Race'). Can be NULL.

byvar

is the categorical variable you want to tabulate by across the columns (needs to be in quotes). Can be NULL.

dat

is the dataset to use for analysis

col

takes the value TRUE or FALSE indicating whether you want column percent (TRUE, default) or row percent (FALSE)

spread

takes the value "range" or "iqr" indicating whether you want (min, max) or (Q1, Q3) in summaries of continuous variables. Defaults to "range".

pval

takes the value TRUE or FALSE indicating whether p-values should be included. Defaults to TRUE. If TRUE, kruskal.test p-values are produced for continuous variables and either fisher.test or chisq.test p-values are produced for categorical variables.

fisher

takes the value TRUE or FALSE. If TRUE, fisher.test p-values are produced. If FALSE, chisq.test p-values are produced.

Value

Returns a dataframe. If there are warnings or errors from kruskal.test, fisher.test, or chisq.test then NA is returned in place of the p-value.