Skip to content
Prev 275871 / 398506 Next

R help with different combinations of vectors of different sizes

On Oct 29, 2011, at 9:08 AM, Suleyman K wrote:

            
You did say "combinations" rather than permutations, so:

 > colSums(combn(0:5, 3))
  [1]  3  4  5  6  5  6  7  7  8  9  6  7  8  8  9 10  9 10 11 12

If you instead meant "permutations", then consider this:

 > rowSums(expand.grid(0:5,0:5, 0:5))
   [1]  0  1  2  3  4  5  1  2  3  4  5  6  2  3  4  5  6  7  3  4  5   
6  7  8  4  5  6  7  8  9  5  6  7
  [34]  8  9 10  1  2  3  4  5  6  2  3  4  5  6  7  3  4  5  6  7  8   
4  5  6  7  8  9  5  6  7  8  9 10
  [67]  6  7  8  9 10 11  2  3  4  5  6  7  3  4  5  6  7  8  4  5  6   
7  8  9  5  6  7  8  9 10  6  7  8
[100]  9 10 11  7  8  9 10 11 12  3  4  5  6  7  8  4  5  6  7  8  9   
5  6  7  8  9 10  6  7  8  9 10 11
[133]  7  8  9 10 11 12  8  9 10 11 12 13  4  5  6  7  8  9  5  6  7   
8  9 10  6  7  8  9 10 11  7  8  9
[166] 10 11 12  8  9 10 11 12 13  9 10 11 12 13 14  5  6  7  8  9 10   
6  7  8  9 10 11  7  8  9 10 11 12
[199]  8  9 10 11 12 13  9 10 11 12 13 14 10 11 12 13 14 15

 > table(rowSums(expand.grid(0:5,0:5, 0:5)))

  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
  1  3  6 10 15 21 25 27 27 25 21 15 10  6  3  1

A056150 Number of combinations for each possible sum when throwing 3  
(normal) dice.
http://oeis.org/A056150
David Winsemius, MD
West Hartford, CT