[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] table formula help...
From: |
Thierry Banel |
Subject: |
Re: [O] table formula help... |
Date: |
Fri, 12 Dec 2014 22:04:31 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 |
Le 12/12/2014 18:15, Michael Brand a écrit :
> Hi Thierry
>
>
>> Here is how the spreadsheet handles those cases (without modifiers):
>> | | | | sum | mean | prod |
>> |---+---+---+-----+-----------+------|
>> | 1 | 2 | 3 | 6 | 2 | 6 |
>> | | 2 | 3 | 5 | 1.6666667 | 6 |
>> | | | 3 | 3 | 1 | 3 |
>> | | | | 0 | 0 | 1 | <--- see
>> #+TBLFM: $4=vsum($1..$3)::$5=vmean($1..$3)::$6=vprod($1..$3)
> - Isn't the above table content from a different TBLFM with a mode
> string EN for vmean?:
>
> #+TBLFM: $4=vsum($1..$3)::$5=vmean($1..$3);EN::$6=vprod($1..$3)
Absolutely. I should not write mails so late in the night.
>
> - All columns without mode string (Org >= 8.0):
>
> | | | | vsum | vmean | vprod | vmin | vmax |
> |---+---+---+------+-----------+-------+------+------|
> | 1 | 2 | 3 | 6 | 2 | 6 | 1 | 3 |
> | | 2 | 3 | 5 | 2.5 | 6 | 2 | 3 |
> | | | 3 | 3 | 3 | 3 | 3 | 3 |
> | | | | 0 | vmean([]) | 1 | inf | -inf |
> #+TBLFM:
> $4=vsum($1..$3)::$5=vmean($1..$3)::$6=vprod($1..$3)::$7=vmin($1..$3)::$8=vmax($1..$3)
>
> - All columns with mode string EN (Org >= 8.0):
>
> | | | | vsum | vmean | vprod | vmin | vmax |
> |---+---+---+------+-----------+-------+------+------|
> | 1 | 2 | 3 | 6 | 2 | 6 | 1 | 3 |
> | | 2 | 3 | 5 | 1.6666667 | 0 | 0 | 3 |
> | | | 3 | 3 | 1 | 0 | 0 | 3 |
> | | | | 0 | 0 | 0 | 0 | 0 |
> #+TBLFM:
> $4=vsum($1..$3);EN::$5=vmean($1..$3);EN::$6=vprod($1..$3);EN::$7=vmin($1..$3);EN::$8=vmax($1..$3);EN
>
>> This is correct. Orgaggregate should behave in a similar way.
>> Fortunately in its latest version it does.
> Ok, I see the similarity in the case for sum of "no input" with which
> I now agree.
And for vmean on zero-length input:
- Spreadsheet without modifiers: vmean([])
- Orgaggregate: Empty
They agree, in this zero-case both return a special value.
>> * Summary
>> Modifiers are lacking in orgaggregate for it to be fully consistent with
>> the spreadsheet. If someone knowns how to add them easily...
> I would try an approach like
>
> #+TBLNAME: test
> | Item | Value |
> |------+-------|
> | a | |
> | a | 2 |
>
> #+BEGIN: aggregate :table test :cols ("Item" "2 * vsum(Value) + 3 *
> vmean(Value); EN")
> | Item | What column header here? How to specify? |
> |------+------------------------------------------|
> | a | 7 |
> #+END
>
> that has a syntax more towards TBLFM with a Calc expression.
I dreamed about such a syntax when designing orgaggregate in the first
place. But I dismissed it as it was going too far in terms of
re-inventing the wheel.
> It would
> not need a mapping of the aggregation function like in
> orgtbl-aggregate-apply-calc-*-function and would go through these
> steps:
>
> 1) Collect list from aggregated input column "Value":
>
> => '("" "2")
>
> 2) Convert list to Calc vector depending on mode string, see also
> test-org-table/references/mode-string-EN and
> test-org-table/org-table-make-reference/mode-string-EN with their
> siblings:
>
> (org-table-make-reference '("" "2") t t nil) => "[0,2]"
>
> 3) Detach Calc expression from mode string and replace input header
> "Value" (possibly several and different input headers per output
> header) with Calc vector:
>
> "2 * vsum(Value) + 3 * vmean(Value); EN" =>
> "2 * vsum([0,2]) + 3 * vmean([0,2])"
>
> 4) Delegate everything else to Calc, just as org-table-eval-formula
> does:
>
> (calc-eval "2 * vsum([0,2]) + 3 * vmean([0,2])") => "7"
>
> It is the same that happens already without orgaggregate as
>
> | Value |
> |-------|
> | |
> | 2 |
> |-------|
> | 7 |
> #+TBLFM: @>$1 = 2 * vsum(@address@hidden) + 3 * vmean(@address@hidden); EN
>
> where the table formula debugger logs:
>
> Orig: 2 * vsum(@address@hidden) + 3 * vmean(@address@hidden)
> $xyz-> 2 * vsum(@address@hidden) + 3 * vmean(@address@hidden)
> @r$c-> 2 * vsum([0,2]) + 3 * vmean([0,2])
> $1-> 2 * vsum([0,2]) + 3 * vmean([0,2])
> Result: 7
>
> Mode strings other than "E" and "N" for orgaggregate should then not
> be too far away, see also org-table-eval-formula.
>
> Michael
>
Seems doable.
Would tie the spreadsheet and orgaggregate seamlessly.
Very appealing!
Are you willing to help me implement those steps?
Thierry
- Re: [O] table formula help..., (continued)
- Re: [O] table formula help..., Thierry Banel, 2014/12/07
- Re: [O] table formula help..., Michael Brand, 2014/12/08
- Re: [O] table formula help..., Thierry Banel, 2014/12/08
- Re: [O] table formula help..., Michael Brand, 2014/12/09
- Re: [O] table formula help..., Thierry Banel, 2014/12/09
- Re: [O] table formula help..., Thierry Banel, 2014/12/09
- Re: [O] table formula help..., Thierry Banel, 2014/12/09
- Re: [O] table formula help..., Michael Brand, 2014/12/10
- Re: [O] table formula help..., Thierry Banel, 2014/12/10
- Re: [O] table formula help..., Michael Brand, 2014/12/12
- Re: [O] table formula help...,
Thierry Banel <=
- Re: [O] table formula help..., Michael Brand, 2014/12/13