ol = c(1:7, 99)
var_lab(ol) = "Liking"
val_lab(ol) = num_lab("
1 Disgusting
2 Very Poor
3 Poor
4 So-so
5 Good
6 Very good
7 Excellent
99 Hard to say
")
cro(subtotal(ol, BOTTOM = 1:3, TOP = 6:7, position = "top"))
# example with hide
cro(subtotal(ol, TOP1 = hide(7), TOP2 = hide(6:7), TOP3 = 5:7, BOTTOM = 1:3, position = "top"))
# autolabelling
cro(subtotal(ol, 1:3, 6:7))
# replace original codes and another way of autolabelling
cro(net(ol, 1:3, 6:7, new_label = "range", prefix = "NET "))
# unhide
cro(net(ol, 1:3, unhide(6:7), new_label = "range", prefix = "NET "))
# character variable and criteria usage
items = c("apple", "banana", "potato", "orange", "onion", "tomato", "pineapple")
cro(
subtotal(items,
"TOTAL FRUITS" = like("*ap*") | like("*an*"),
"TOTAL VEGETABLES" = like("*to*") | like("*on*"),
position = "bottom")
)
# 'tab_net_*' usage
data(mtcars)
mtcars = apply_labels(mtcars,
mpg = "Miles/(US) gallon",
am = "Transmission",
am = c("Automatic" = 0,
"Manual"=1),
gear = "Number of forward gears",
gear = c(
One = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5
)
)
mtcars %>%
tab_cells(mpg) %>%
tab_net_cells("Low mpg" = less(mean(mpg)), "High mpg" = greater_or_equal(mean(mpg))) %>%
tab_cols(total(), am) %>%
tab_stat_cases() %>%
tab_pivot()
mtcars %>%
tab_cells(mpg) %>%
tab_rows(gear) %>%
tab_subtotal_rows(1:2, 3:4, "5 and more" = greater(4)) %>%
tab_stat_mean() %>%
tab_pivot()
Run the code above in your browser using DataLab