combination from different vectors

后端 未结 1 586
囚心锁ツ
囚心锁ツ 2021-01-25 21:18

I have some vectors like this

V1 = c(1,2,3,4,5)
V2 = c(7,8,9,10,11)
V3 = c(15,16,17,18,19)
V4 = c(3,4,5,6,7)

I would like to get all possible c

1条回答
  •  滥情空心
    2021-01-25 21:34

    If I understand your questions correctly, you are probably looking for expand.grid:

    > expand.grid( V1=V1, V2=V2, V3=V3, V4=V4 )[1:5,]
      V1 V2 V3 V4
    1  1  7 15  3
    2  2  7 15  3
    3  3  7 15  3
    4  4  7 15  3
    5  5  7 15  3
    ...
    

    This will yield all a data.frame with one row per combination

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