Translate

Tuesday, 15 August 2017

Creating combinations of elements using expand.grid

To generate all combinations of elements from a pair or multiples of vectors, use expand.grid().
 
 
expand.grid(c(1:3), LETTERS[1:3]) 
 

  Var1 Var2
1    1    A
2    2    A
3    3    A
4    1    B
5    2    B
6    3    B
7    1    C
8    2    C
9    3    C
 
   
 
 
expand.grid(c(1:3),LETTERS[1:3],letters[1:2])
 
 
   Var1 Var2 Var3
1     1    A    a
2     2    A    a
3     3    A    a
4     1    B    a
5     2    B    a
6     3    B    a
7     1    C    a
8     2    C    a
9     3    C    a
10    1    A    b
11    2    A    b
12    3    A    b
13    1    B    b
14    2    B    b
15    3    B    b
16    1    C    b
17    2    C    b
18    3    C    b

 
 


1 comment:

  1. Great presentation of ROC Curve Data Science form of blog and ROC Curve Data Science tutorial. Very helpful for beginners like us to understand ROC Curve Data Science course. if you're interested to have an insight on ROC Curve Data Science training do watch this amazing tutorial.:-https://www.youtube.com/watch?v=G_pvQYUm8Ik

    ReplyDelete