You are probably looking for outer() or the binary operator alias %o% :
> c(2,3,4) %o% c(1,2) [,1] [,2] [1,] 2 4 [2,] 3 6 [3,] 4 8 > outer(c(2,3,4), c(1,2)) [,1] [,2] [1,] 2 4 [2,] 3 6 [3,] 4 8
In your case, outer() offers the flexibility to specify a function to apply to combinations; %o% only the multiplication function * is applied. For your example and data
mph <- function(d, rpm) { cir <- pi * d cir * rpm / 63360 * 60 } > outer(c(20,26,29), c(150,350), FUN = mph) [,1] [,2] [1,] 8.924979 20.82495 [2,] 11.602473 27.07244 [3,] 12.941220 30.19618
source share