Решение Base R:
# For each combination:
res <- data.frame(round(prop.table(table(abcd)) * 100, 2))
# For each var separately:
res$total_a_cat <- ave(res$Freq, res$a, FUN = sum)
res$total_b_cat <- ave(res$Freq, res$b, FUN = sum)
Данные:
abcd <-
structure(list(
a = structure(
c(3L, 3L, 2L, 1L, 2L, 3L, 2L, 1L,
1L),
.Label = c("neutral", "no", "yes"),
class = "factor"
),
b = structure(
c(2L,
3L, 2L, 2L, 2L, 1L, 3L, 1L, 1L),
.Label = c("neutral", "no",
"yes"),
class = "factor"
)
),
class = "data.frame",
row.names = c(NA,-9L))