#whole table
crosstable(iris)
crosstable(mtcars)
crosstable(mtcars2)
#tidyselection, custom functions
library(dplyr)
crosstable(mtcars2, c(ends_with("t"), starts_with("c")), by=vs,
funs=c(mean, quantile), funs_arg=list(probs=c(.25,.75)))
#margin and totals, multiple by
crosstable(mtcars2, c(disp, cyl), by=c(am, vs),
margin=c("row", "col"), total = "both")
#predicate selection, correlation, effect calculation
crosstable(mtcars2, where(is.numeric), by=hp, effect=TRUE)
#lambda selection & statistical tests
crosstable(mtcars2, ~is.numeric(.x) && mean(.x)>50, by=vs, test=TRUE)
#Dates
mtcars2$my_date = as.Date(mtcars2$hp , origin="2010-01-01") %>% set_label("Some nonsense date")
crosstable(mtcars2, my_date, by=vs, date_format="%d/%m/%Y")
#Survival data (using formula syntax)
library(survival)
crosstable(aml, Surv(time, status) ~ x, times=c(0,15,30,150), followup=TRUE)
#Patterns
crosstable(mtcars2, vs, by=am, percent_digits=0,
percent_pattern="{n} ({p_col} / {p_row})")
crosstable(mtcars2, vs, by=am, percent_digits=0,
percent_pattern="N={n} \np[95%CI] = {p_col} [{p_col_inf}; {p_col_sup}]")
str_high="n>5"; str_lo="n<=5"
crosstable(mtcars2, vs, by=am, percent_digits=0,
percent_pattern="col={p_col}, row={p_row} ({ifelse(n<5, str_lo, str_high)})")
Run the code above in your browser using DataLab