У меня есть фрейм данных
structure(list(name = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 1L, 12L, 10L, 14L, 11L, 13L, 14L), .Label = c("a", "b",
"c", "d", "e", "f", "g", "h", "i", "p", "q", "r", "s", "w"), class = "factor"),
total = c(1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 1, 4, 9, 3, 4, 6),
freq = c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.2, 0.3, 0.4,
0.1, 0.4, 0.9, 0.3, 0.4, 0.6), group = structure(c(1L, 1L,
1L, 4L, 4L, 4L, 2L, 2L, 2L, 5L, 5L, 5L, 3L, 3L, 6L, 6L), .Label = c("X_Group1",
"X_Group2", "X_Group3", "Y_Group1", "Y_Group2", "Y_Group3"
), class = "factor")), class = "data.frame", row.names = c(NA,
-16L))
Можно ли преобразовать его, как показано ниже
result <- structure(list(X_Group1.name = structure(1:3, .Label = c("a",
"b", "c"), class = "factor"), X_Group1.total = c(1, 2, 3), X_Group1.freq = c(0.1,
0.2, 0.3), X_Group1.group = structure(c(1L, 1L, 1L), .Label = "X_Group1", class = "factor"),
X_Group2.name = structure(1:3, .Label = c("g", "h", "i"), class = "factor"),
X_Group2.total = c(7, 2, 3), X_Group2.freq = c(0.7, 0.2,
0.3), X_Group2.group = structure(c(1L, 1L, 1L), .Label = "X_Group2", class = "factor"),
X_Group3.name = structure(3:1, .Label = c("NA", "q", "w"), class = "factor"),
X_Group3.total = structure(c(2L, 1L, 3L), .Label = c("3",
"9", "NA"), class = "factor"), X_Group3.freq = structure(c(2L,
1L, 3L), .Label = c("0.3", "0.9", "NA"), class = "factor"),
X_Group3.group = structure(c(2L, 2L, 1L), .Label = c("NA",
"X_Group3"), class = "factor"), Y_Group1.name = structure(1:3, .Label = c("d",
"e", "f"), class = "factor"), Y_Group1.total = c(4, 5, 6),
Y_Group1.freq = c(0.4, 0.5, 0.6), Y_Group1.group = structure(c(1L,
1L, 1L), .Label = "Y_Group1", class = "factor"), Y_Group2.name = structure(c(1L,
3L, 2L), .Label = c("a", "p", "r"), class = "factor"), Y_Group2.total = c(4,
1, 4), Y_Group2.freq = c(0.4, 0.1, 0.4), Y_Group2.group = structure(c(1L,
1L, 1L), .Label = "Y_Group2", class = "factor"), Y_Group3.name = structure(c(2L,
3L, 1L), .Label = c("NA", "s", "w"), class = "factor"), Y_Group3.total = structure(1:3, .Label = c("4",
"6", "NA"), class = "factor"), Y_Group3.freq = structure(1:3, .Label = c("0.4",
"0.6", "NA"), class = "factor"), Y_Group3.group = structure(c(2L,
2L, 1L), .Label = c("NA", "Y_Group3"), class = "factor")), class = "data.frame", row.names = c(NA,
-3L))
Я пробовал разделить, а затем привязать их по горизонтали с помощью bind_col и любит, но это не так работай.
Спасибо!