From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xiao-Yong Jin Subject: Table calculation Date: Sun, 10 Dec 2006 14:32:42 -0500 Message-ID: <86k60zsg11.fsf@presario.homeunix.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GtUQh-00084Y-0t for emacs-orgmode@gnu.org; Sun, 10 Dec 2006 14:33:43 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GtUQe-00082r-TU for emacs-orgmode@gnu.org; Sun, 10 Dec 2006 14:33:42 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GtUQe-00082o-Op for emacs-orgmode@gnu.org; Sun, 10 Dec 2006 14:33:40 -0500 Received: from [128.59.29.8] (helo=brinza.cc.columbia.edu) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1GtUQe-0001Dp-P8 for emacs-orgmode@gnu.org; Sun, 10 Dec 2006 14:33:40 -0500 Received: from presario.homeunix.org (dyn-carl-201-231.dyn.columbia.edu [160.39.201.231]) (user=xj2106 mech=PLAIN bits=0) by brinza.cc.columbia.edu (8.13.7/8.13.6) with ESMTP id kBAJXSFR018456 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sun, 10 Dec 2006 14:33:33 -0500 (EST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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---