From: Michael Brand <michael.ch.brand@gmail.com>
To: Thierry Banel <tbanelwebmin@free.fr>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: table formula help...
Date: Fri, 12 Dec 2014 18:15:25 +0100 [thread overview]
Message-ID: <CALn3zojJvmMduDajfvqqwC4AjRbyRw0T8CKQ622M8WoryPYifQ@mail.gmail.com> (raw)
In-Reply-To: <5488CF51.8000006@free.fr>
Hi Thierry
On Wed, Dec 10, 2014 at 11:55 PM, Thierry Banel <tbanelwebmin@free.fr> wrote:
> Le 10/12/2014 22:06, Michael Brand a écrit :
>> If this function would follow its docstring by having "(if (cdr vec)"
>> also for sum, min, max and prod then the user could benefit from
>> adding "E" and/or "N" or not in the mode string of the TBLFM:
>
> To further process the aggregations?
Yes, in the TBLFM of the result table.
> 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)
- 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.
> * 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. 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(@I..@II) + 3 * vmean(@I..@II); EN
where the table formula debugger logs:
Orig: 2 * vsum(@I..@II) + 3 * vmean(@I..@II)
$xyz-> 2 * vsum(@I..@II) + 3 * vmean(@I..@II)
@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
next prev parent reply other threads:[~2014-12-12 17:15 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-06 5:42 table formula help Eric Abrahamsen
2014-12-06 7:37 ` Thomas S. Dye
2014-12-06 8:05 ` Michael Brand
2014-12-06 8:32 ` Eric Abrahamsen
2014-12-06 22:49 ` Thierry Banel
2014-12-07 2:05 ` Eric Abrahamsen
2014-12-07 3:25 ` Eric Abrahamsen
2014-12-07 9:20 ` Thierry Banel
2014-12-07 9:40 ` Michael Brand
2014-12-07 10:02 ` Thierry Banel
2014-12-07 10:26 ` Michael Brand
2014-12-07 14:51 ` Thierry Banel
2014-12-07 16:13 ` Thierry Banel
2014-12-07 16:48 ` Michael Brand
2014-12-08 21:12 ` Thierry Banel
2014-12-08 22:32 ` Thierry Banel
2014-12-10 21:08 ` Michael Brand
2014-12-08 3:52 ` Eric Abrahamsen
2014-12-07 9:39 ` Michael Brand
2014-12-07 9:55 ` Thierry Banel
2014-12-07 21:57 ` Thierry Banel
2014-12-08 18:02 ` Michael Brand
2014-12-08 21:57 ` Thierry Banel
2014-12-09 5:54 ` Michael Brand
2014-12-09 18:12 ` Thierry Banel
2014-12-09 19:01 ` Thierry Banel
2014-12-09 22:35 ` Thierry Banel
2014-12-10 21:06 ` Michael Brand
2014-12-10 22:55 ` Thierry Banel
2014-12-12 17:15 ` Michael Brand [this message]
2014-12-12 21:04 ` Thierry Banel
2014-12-13 18:27 ` Michael Brand
2015-01-25 22:21 ` Thierry Banel
2015-01-26 2:48 ` Eric Abrahamsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALn3zojJvmMduDajfvqqwC4AjRbyRw0T8CKQ622M8WoryPYifQ@mail.gmail.com \
--to=michael.ch.brand@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=tbanelwebmin@free.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).