fork download
  1. x <- matrix(c(letters[1:10], LETTERS[1:10]), 2, byrow = T)
  2. print(x)
  3. # [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  4. # [1,] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
  5. # [2,] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
  6. ind <- as.matrix(expand.grid(replicate(10, 1:2, simplify = F)))
  7. res <- t(apply(ind, 1, function(k) {
  8. diag(x[k,])
  9. }))
  10. head(res)
  11. # [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  12. # [1,] "a" "c" "e" "g" "i" "k" "m" "o" "q" "s"
  13. # [2,] "b" "c" "e" "g" "i" "k" "m" "o" "q" "s"
  14. # [3,] "a" "d" "e" "g" "i" "k" "m" "o" "q" "s"
  15. # [4,] "b" "d" "e" "g" "i" "k" "m" "o" "q" "s"
  16. # [5,] "a" "c" "f" "g" "i" "k" "m" "o" "q" "s"
  17. # [6,] "b" "c" "f" "g" "i" "k" "m" "o" "q" "s"
  18. tail(res)
  19. # [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  20. # [1019,] "a" "B" "c" "D" "E" "F" "G" "H" "I" "J"
  21. # [1020,] "A" "B" "c" "D" "E" "F" "G" "H" "I" "J"
  22. # [1021,] "a" "b" "C" "D" "E" "F" "G" "H" "I" "J"
  23. # [1022,] "A" "b" "C" "D" "E" "F" "G" "H" "I" "J"
  24. # [1023,] "a" "B" "C" "D" "E" "F" "G" "H" "I" "J"
  25. # [1024,] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
  26.  
  27. dim(res) # totally 1024 combinations
  28.  
  29.  
  30. res[1, ]
  31. res[2, ]
  32. #...
  33. res[1024, ]
  34.  
Success #stdin #stdout 0.22s 42048KB
stdin
Standard input is empty
stdout
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] "a"  "b"  "c"  "d"  "e"  "f"  "g"  "h"  "i"  "j"  
[2,] "A"  "B"  "C"  "D"  "E"  "F"  "G"  "H"  "I"  "J"  
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] "a"  "b"  "c"  "d"  "e"  "f"  "g"  "h"  "i"  "j"  
[2,] "A"  "b"  "c"  "d"  "e"  "f"  "g"  "h"  "i"  "j"  
[3,] "a"  "B"  "c"  "d"  "e"  "f"  "g"  "h"  "i"  "j"  
[4,] "A"  "B"  "c"  "d"  "e"  "f"  "g"  "h"  "i"  "j"  
[5,] "a"  "b"  "C"  "d"  "e"  "f"  "g"  "h"  "i"  "j"  
[6,] "A"  "b"  "C"  "d"  "e"  "f"  "g"  "h"  "i"  "j"  
        [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1019,] "a"  "B"  "c"  "D"  "E"  "F"  "G"  "H"  "I"  "J"  
[1020,] "A"  "B"  "c"  "D"  "E"  "F"  "G"  "H"  "I"  "J"  
[1021,] "a"  "b"  "C"  "D"  "E"  "F"  "G"  "H"  "I"  "J"  
[1022,] "A"  "b"  "C"  "D"  "E"  "F"  "G"  "H"  "I"  "J"  
[1023,] "a"  "B"  "C"  "D"  "E"  "F"  "G"  "H"  "I"  "J"  
[1024,] "A"  "B"  "C"  "D"  "E"  "F"  "G"  "H"  "I"  "J"  
[1] 1024   10
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
 [1] "A" "b" "c" "d" "e" "f" "g" "h" "i" "j"
 [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"