Вот базовое решение R с prop.table
на table
отсчетов.
prop.table(table(df1[c('Gender', 'Groups')]))
# Groups
#Gender G1 G2 G3 G5 G6 G8 G9
# F 0.1 0.0 0.2 0.0 0.0 0.0 0.1
# M 0.0 0.1 0.0 0.2 0.1 0.1 0.1
Данные в dput
формате
df1 <-
structure(list(SubjectId = c(1L, 2L, 3L, 4L, 5L, 996L, 997L,
998L, 999L, 1000L), Gender = c("F", "M", "M", "M", "M", "F",
"M", "F", "M", "F"), Groups = c("G3", "G6", "G2", "G5", "G5",
"G1", "G8", "G3", "G9", "G9"), ExtraCalories = c(-1310, -920.79656,
-25.39517, 169.25645, -340.67235, 464.82543, -323.65136, 77.92138,
-237.837, -400.44831), GW = c(0, 4.331278, 4.727376, 3.543941,
4.591774, 5.933792, 5.024453, 5.383686, 5.423941, 6.837965)),
class = "data.frame", row.names = c("1:", "2:", "3:", "4:", "5:",
"996:", "997:", "998:", "999:", "1000:"))