emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Table calculation
@ 2016-02-20 19:41 Brett Presnell
  2016-02-20 21:13 ` Michael Brand
  0 siblings, 1 reply; 4+ messages in thread
From: Brett Presnell @ 2016-02-20 19:41 UTC (permalink / raw)
  To: emacs-orgmode


In the following table, the last row gives the number of empty cells
following the last nonempty cell in each column (except the first column
of course).  I would like to create a TBLFM formula that does this
calculation for me automatically.  Some time ago I tried using
org-lookup-last and org-lookup-all for this, but I never got it to work.
Any ideas/solutions?

|   Date | AA | BB | CC | DD | EE | FF | GG | HH | II | JJ | KK | LL | MM |
|--------+----+----+----+----+----+----+----+----+----+----+----+----+----|
|      / | <> | <> | <> | <> | <> | <> | <> | <> | <> | <> | <> | <> | <> |
| 201005 |    |    |    |    |  1 |    |    |  1 |    |    |    |  1 |    |
| 201008 |    |    |    |  1 |    |    |    |    |    |    |    |    |    |
| 201012 |    |    |    |    |    |    |    |    |    |    |    |    |    |
| 201105 |    |    |    |    |    |  1 |    |    |    |    |    |    |    |
| 201108 |    |    |    |    |    |    |  1 |    |    |    |    |    |    |
| 201112 |    |    |    |    |    |    |    |    |    |  1 |    |    |    |
| 201205 |    |    |    |    |    |    |    |    |    |    |    |    |    |
| 201208 |    |    |    |    |    |    |    |    |    |    |    |    |    |
| 201212 |    |    |    |    |    |    |    |    |  1 |    |    |    |    |
| 201305 |    |    |  1 |    |    |    |    |  2 |    |    |  1 |    |    |
| 201308 |  1 |    |    |    |    |    |    |    |    |    |    |    |    |
| 201312 |    |    |    |    |    |    |    |    |    |    |    |    |  1 |
| 201405 |    |    |    |    |    |    |    |  1 |    |    |    |  1 |    |
| 201408 |    |  1 |    |    |    |    |    |    |    |    |    |    |    |
| 201412 |    |    |    |    |  1 |    |    |    |    |    |    |    |    |
| 201505 |    |    |    |  1 |    |    |    |    |    |    |    |    |    |
| 201508 |    |    |    |    |    |    |    |    |  1 |    |    |    |    |
| 201512 |    |    |    |    |    |    |  1 |    |    |    |    |    |    |
| 201605 |    |    |    |    |    |    |    |    |    |    |    |    |    |
|--------+----+----+----+----+----+----+----+----+----+----+----+----+----|
|        |  8 |  5 |  9 |  3 |  4 | 15 |  1 |  6 |  2 | 13 |  9 |  6 |  7 |

^ permalink raw reply	[flat|nested] 4+ messages in thread
* Table calculation
@ 2006-12-10 19:32 Xiao-Yong Jin
  0 siblings, 0 replies; 4+ messages in thread
From: Xiao-Yong Jin @ 2006-12-10 19:32 UTC (permalink / raw)
  To: emacs-orgmode

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---

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-02-20 22:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-20 19:41 Table calculation Brett Presnell
2016-02-20 21:13 ` Michael Brand
2016-02-20 22:48   ` Brett Presnell
  -- strict thread matches above, loose matches on Subject: below --
2006-12-10 19:32 Xiao-Yong Jin

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).