-1

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

Sotos
  • 51,121
  • 6
  • 32
  • 66
Codezy
  • 662
  • 5
  • 17

1 Answers1

1

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"
Prradep
  • 5,506
  • 5
  • 43
  • 84