xtabs()
и aggregate()
делают работу:
as.data.frame.matrix(xtabs(Column_3 ~ Column_1 + Column_2,
aggregate(Column_3 ~ Column_1 + Column_2, df, mean)))
# output
(15-25] (25-35] (35-45]
(0-1] 31.5 0 0.0
(1-2] 12.0 15 0.0
(2-3] 0.0 10 25.0
(3-4] 0.0 10 0.0
(4-5] 0.0 0 29.5
# data
df <- structure(list(Column_1 = c("(0-1]", "(2-3]", "(4-5]", "(0-1]",
"(2-3]", "(1-2]", "(1-2]", "(3-4]", "(4-5]"), Column_2 = c("(15-25]",
"(35-45]", "(35-45]", "(15-25]", "(25-35]", "(25-35]", "(15-25]",
"(25-35]", "(35-45]"), Column_3 = c(58L, 25L, 50L, 5L, 10L, 15L,
12L, 10L, 9L)), .Names = c("Column_1", "Column_2", "Column_3"
), class = "data.frame", row.names = c(NA, -9L))