Louis Plough
2010-Nov-01 17:46 UTC
[R] how to get all possible combinations including the diagonal using "combn"
Hi, I am trying to generate all possible permutations (choose 2) of a vector, b, for example--using 'combn' the combinations in only one direction are generated...> b<-c(.1,.2,.3) > combn(b,2)[,1] [,2] [,3] [1,] 0.1 0.1 0.2 [2,] 0.2 0.3 0.3 [1,] 0.1 0.2 0.3 0.2 0.3 0.3 These should also be there. [2,] 0.1 0.2 0.3 0.1 0.1 0.2 Is there another R function that can do this?? Thanks, Louis [[alternative HTML version deleted]]
Marc Schwartz
2010-Nov-01 17:51 UTC
[R] how to get all possible combinations including the diagonal using "combn"
On Nov 1, 2010, at 12:46 PM, Louis Plough wrote:> Hi, > I am trying to generate all possible permutations (choose 2) of a vector, b, > for example--using 'combn' the combinations in only one direction are > generated... > >> b<-c(.1,.2,.3) >> combn(b,2) > [,1] [,2] [,3] > [1,] 0.1 0.1 0.2 > [2,] 0.2 0.3 0.3 > > [1,] 0.1 0.2 0.3 0.2 0.3 0.3 These > should also be there. > [2,] 0.1 0.2 0.3 0.1 0.1 0.2 > > Is there another R function that can do this?? > > Thanks, > LouisSee ?expand.grid b <- c(.1, .2, .3)> expand.grid(b, b)Var1 Var2 1 0.1 0.1 2 0.2 0.1 3 0.3 0.1 4 0.1 0.2 5 0.2 0.2 6 0.3 0.2 7 0.1 0.3 8 0.2 0.3 9 0.3 0.3 HTH, Marc Schwartz