emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Xiao-Yong Jin <xj2106@columbia.edu>
To: emacs-orgmode@gnu.org
Subject: Table calculation
Date: Sun, 10 Dec 2006 14:32:42 -0500	[thread overview]
Message-ID: <86k60zsg11.fsf@presario.homeunix.org> (raw)

Hi, in order to calculate the average with some invalid column, I
managed to write a short elisp script.  You can see the difference
between the `0' and the `-' in this table:

| ! |  P1 |  P2 | P3  |  P4 |  P5 | Average |
| # | 3.6 | 4.0 | 4.8 |   0 | 4.7 |    3.42 |
| # | 5.0 | 3.3 | -   | 4.7 | 4.0 |    4.25 |
#+TBLFM: $7='(let ((data '("$P1" "$P2" "$P3" "$P4" "$P5"))
                   (n 0)
                   (total 0))
                  (while data
                    (unless (string= (car data) "-")
                      (setq total
                        (+ total (string-to-number (car data))))
                      (setq n (1+ n)))
                    (setq data (cdr data)))
                  (/ total n));%.2f

It is reformatted to be more readable, since one cannot put a
multi-line expression in #+TBLFM.

I admit it is really painful to do this.  I want to know if anyone
knows how I can simplify this a bit, or if there is a short cut to do
this.  I'm not familiar with the internal implementation of org table,
but is there any possibility to make it as a built-in function that I
can put it somewhere in the same org file so that I can easily do some
thing like mymean($P1..$P5)?

Thanks,
Xiao-Yong
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---

             reply	other threads:[~2006-12-10 19:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-10 19:32 Xiao-Yong Jin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-02-20 19:41 Table calculation Brett Presnell
2016-02-20 21:13 ` Michael Brand
2016-02-20 22:48   ` Brett Presnell

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=86k60zsg11.fsf@presario.homeunix.org \
    --to=xj2106@columbia.edu \
    --cc=emacs-orgmode@gnu.org \
    /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).