-2

I'm trying to create a list of combinations of strings using combn() with paste0 as the function, but all I get back is the matrix of combinations. What am I doing wrong?

Example:

combn(LETTERS[1:5],3, FUN=paste0)

Gives me:

     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] "A"  "A"  "A"  "A"  "A"  "A"  "B"  "B"  "B"  "C"  
[2,] "B"  "B"  "B"  "C"  "C"  "D"  "C"  "C"  "D"  "D"  
[3,] "C"  "D"  "E"  "D"  "E"  "E"  "D"  "E"  "E"  "E"    

When what I expected to get was something like:

[1] "ABC" "ABD" "ABE" "ACD" "ACE" "ADE" ...

What did I miss?

iod
  • 7,412
  • 2
  • 17
  • 36
  • 8
    This has nothing to do with `combn`; `paste0(c("a", "b", "c"))` vs `paste0(c("a", "b", "c"), collapse = "")` – Henrik Sep 24 '18 at 13:16
  • THANKS! This has been frustrating me since yesterday. Didn't think to check is paste0 was the problem. – iod Sep 24 '18 at 13:17

1 Answers1

4

Can you use this command and see if it works ? It worked for me.

combn(LETTERS[1:5],3, FUN=paste0, collapse = "")
H Dave
  • 306
  • 1
  • 11