I want to make a vector which contains all possibilities of specific characters in selected length. For example, characters are A
, B
, M
, and selected length are two, then the output should be AA, AB, AM, BA, BB, BM, MA, MB, MM
.
Thank you
Try the following approach which would give all the possible combinations of 2-Letters from the given list of letters.
do.call(paste0,expand.grid(rep(list(c('A', 'B', 'M')), 2)))
# [1] "AA" "BA" "MA" "AB" "BB" "MB" "AM" "BM" "MM"