# All possible combination of summation of vectors

I have 3 vectors, A, B, C. They all have the same number of rows. What I am looking for is the all possible combination of summation of vectors. For this example, I want to have A+B, A+C, B+C, and A+B+C. Is there any command/package that can do that? In another words, I want all possible linear combinations of the 3 vectors with linear coefficients of 1. My real problem involves a lot of vectors, not just 3. I simplified it here.

Thanks

it's not entirely what you are looking for but maybe it provides some direction.

``````a <- seq(1, 5)
b <- seq(1, 5)
c <- seq(1, 5)

library(tidyverse)
crossing(a, b, c) %>%
mutate(sum_all=a+b+c)
#> # A tibble: 125 x 4
#>        a     b     c sum_all
#>    <int> <int> <int>   <int>
#>  1     1     1     1       3
#>  2     1     1     2       4
#>  3     1     1     3       5
#>  4     1     1     4       6
#>  5     1     1     5       7
#>  6     1     2     1       4
#>  7     1     2     2       5
#>  8     1     2     3       6
#>  9     1     2     4       7
#> 10     1     2     5       8
#> # ... with 115 more rows
``````

Created on 2019-12-06 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.