I am looking for a way to multiply 2 columns element by element and then sum the resulting vector. I have the following example:
| | | col1 | enable |
|---+-------+------+--------|
| | | 1 | 1 |
| | | 3 | 0 |
| | | | 0 |
| | | 7 | 1 |
|---+-------+------+--------|
| # | sum | 11 | 2 |
| # | value | | |
#+TBLFM: @6$3=vsum(@I$3..@II$3);N::@6$4=vsum(@I$4..@II$4);N
Now I want to add up all values of column col1
, where there is a 1
in the enable
column. The enable
column determins, whether the value in column col1
is mathematically considered, because multiplied by 0
, it will become an addend of 0
in the sum.
Mathematically speaking I want to:
result = sum_{i=0}^i=2 (col1_i * enable_i)
How can I achieve this?
I found inner
on https://www.gnu.org/software/emacs/manual/html_node/calc/Generalized-Products.html#Generalized-Products and https://www.gnu.org/software/emacs/manual/html_node/calc/Function-Index.html#Function-Index, but do no understand how to make use of it or whether it is what I am looking for (not so firm in the terminology).
If the answer is, that this is not possible with a GNU Emacs Calc formula, that's also fine and good to know, but I think it should be possible, as it seems rather basic.
I would like to avoid having to add an extra column for the products and then summing that. The more clutter I can avoid, the better, as this table might get much wider in the future.