Multiplying vector combinations

后端 未结 2 842
暗喜
暗喜 2020-12-11 06:36

Normal R vector multiplication, only multiplies vectors once, or recycles the shorter vector. IE:

> c(2,3,4) * c(1,2)
[1] 2 6 4
Warning message:
In c(2, 3         


        
2条回答
  •  猫巷女王i
    2020-12-11 07:35

    I believe the function you're looking for is outer

    > outer(cir, rpm, function(X, Y) X * Y / 63360 * 60)
              [,1]     [,2]
    [1,]  8.924979 20.82495
    [2,] 11.602473 27.07244
    [3,] 12.941220 30.19618
    

    In this case you could clean up the notation a bit:

    outer(cir, rpm / 63360 * 60)
    

提交回复
热议问题