data.table::setDTthreads(2)
data(mtcars)
# apply labels
mtcars = apply_labels(mtcars,
mpg = "Miles/(US) gallon",
cyl = "Number of cylinders",
disp = "Displacement (cu.in.)",
hp = "Gross horsepower",
drat = "Rear axle ratio",
wt = "Weight (lb/1000)",
qsec = "1/4 mile time",
vs = "V/S",
vs = c("V-engine" = 0, "Straight engine" = 1),
am = "Transmission (0 = automatic, 1 = manual)",
am = c(automatic = 0, manual = 1),
gear = "Number of forward gears",
carb = "Number of carburetors"
)
# table by 'am'
tab1 = cross_cpct(mtcars, gear, am)
# table with percents
tab2 = cross_cpct(mtcars, gear, vs)
# combine tables
tab1 %>% merge(tab2)
# complex tables
# table with counts
counts = cross_cases(mtcars, list(vs, am, gear, carb), list("Count"))
# table with percents
percents = cross_cpct(mtcars, list(vs, am, gear, carb), list("Column, %"))
# combine tables
counts %>% merge(percents)
Run the code above in your browser using DataLab