I want to make 5 data into 3 groups with the condition that all data is in a group. Suppose the data I have (A, B, C, D, E). Then the possible combinations to be made into 3 groups are as follows.

I want to make 5 data into 3 groups with the condition that all data is in a group. Suppose the data I have (A, B, C, D, E). Then the possible combinations to be made into 3 groups are as follows.

jay.sf
On
Using combn.
res <- lapply(2:3, \(m, d) {
cb <- t(combn(LETTERS[1:5], m))
if (m == 2) {
apply(cb, 1, paste, collapse='')
} else {
cb[order(-seq_len(choose(5, m))), ]
}
}) |> do.call(what=cbind) |> as.data.frame()
res
# [,1] [,2] [,3] [,4]
# [1,] "AB" "A" "B" "C"
# [2,] "AC" "A" "B" "D"
# [3,] "AD" "A" "B" "E"
# [4,] "AE" "A" "C" "D"
# [5,] "BC" "A" "C" "E"
# [6,] "BD" "A" "D" "E"
# [7,] "BE" "B" "C" "D"
# [8,] "CD" "B" "C" "E"
# [9,] "CE" "B" "D" "E"
# [10,] "DE" "C" "D" "E"
Copyright © 2021 Jogjafile Inc.
Perhaps not the smartest approach, but you could use
This returns