Quickly generate the cartesian product of a matrix

后端 未结 5 1956
隐瞒了意图╮
隐瞒了意图╮ 2021-02-09 04:34

Let\'s say I have a matrix x which contains 10 rows and 2 columns. I want to generate a new matrix M that contains each unique pair of rows from

5条回答
  •  逝去的感伤
    2021-02-09 04:49

    I'm not quite grokking what you are doing so I'll just throw out something that may, or may not help.

    Here's what I think of as the Cartesian product of the two columns:

    expand.grid(x[,1],x[,2])
    

提交回复
热议问题