当使用文本而不是带标签的数字作为输入时,如何使用自定义表格显示显着差异?(在每个单元格中应该是 + 或 -)。
#Generate data
aw = function(n) {
sample(x = c("Aware","Consider","Buy"), n, replace = T, prob = c(0.1, 0.4, 0.5))
}
awa<-aw(3000)
gen = function(n) {
sample(x = c("Male","Female"), n, replace = T, prob = c(0.8, 0.2))
}
gende<-gen(3000)
ag = function(n) {
sample(x = c("<20","20 to 50","50+"), n, replace = T, prob = c(0.3, 0.2, 0.5))
}
age<-ag(3000)
data<-data.frame(awa,gende,age)
#Banner create
banner = calc(data, list(total(), gende,age))
#Custom table with significant differences calculated relative to total
data %>%
tab_significance_options(compare_type = "adjusted_first_column",subtable_marks = "both",sig_labels_first_column = c("-", "+"),mode = c("append")) %>%
tab_cells(awa) %>%
tab_cols(banner) %>%
tab_stat_cpct() %>%
tab_pivot()