Suppose I have a vector c(1, 2, 3, 4) with no duplicated values. I need a vector c(1 * 2, 1 * 3, 1 * 4, 2 * 3, 2 * 4, 3 * 4), so the multiplication
c(1, 2, 3, 4)
c(1 * 2, 1 * 3, 1 * 4, 2 * 3, 2 * 4, 3 * 4)
We can use combn with anonymous function call
combn
combn(vec, 2, FUN = function(x) x[1] * x[2]) #[1] 2 3 4 6 8 12
vec <- 1:4