Perform 'cross product' of two vectors, but with addition

前端 未结 2 1321
北恋
北恋 2021-01-19 05:11

I am trying to use R to perform an operation (ideally with similarly displayed output) such as

> x<-1:6
> y<-1:6
> x%o%y
     [,1] [,2] [,3] [         


        
相关标签:
2条回答
  • 2021-01-19 05:37

    expand.grid can answer your second question:

    expand.grid(1:6,1:6)
    expand.grid(1:6,1:6,1:4)
    
    0 讨论(0)
  • 2021-01-19 05:53

    Your first question is easily handled by outer:

    outer(1:6,1:6,"+")
    

    For the others, I suggest you try expand.grid, although there are specialized combination and permutation functions out there as well if you do a little searching.

    0 讨论(0)
提交回复
热议问题