0

Consider I have a list of products : For example 100 product names Product$list A B C

I want 100 * 100 combination in Product$list1 and Product$list2 Example:3*3 = 9 combinations

         Product$list1       Product$list2
              A                   B
              A                   C
              B                   A
              B                   C
              C                   A
              C                   B
              A                   A
              B                   B
              C                   C

Can somebody help me how to achieve this in R.

Leeya
  • 170
  • 2
  • 15

1 Answers1

2

You could try combn

 setNames(as.data.frame(t(combn(Product$Col,2))), paste0("Col",1:2))

data

Product <- data.frame(Col=LETTERS[1:3], stringsAsFactors=FALSE)
akrun
  • 874,273
  • 37
  • 540
  • 662
  • solution <- t(combn(LETTERS[1:3], 2)) print(solution) –  Feb 24 '15 at 11:09
  • @Nemo Yes, that was what I earlier posted. Changed it so that if the OP's data is something else, it could still be used. – akrun Feb 24 '15 at 11:11
  • oh, I did not know that ! however, you are always two steps in front of me :-D –  Feb 24 '15 at 12:02