From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adam Porter Subject: Re: Determine min/max values in a table Date: Thu, 03 Aug 2017 04:53:32 -0500 Message-ID: <87a83hou3n.fsf@alphapapa.net> References: <2017-08-02T14-05-32@devnull.Karl-Voit.at> <598242B0.8010004@free.fr> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddCpA-0004aP-24 for emacs-orgmode@gnu.org; Thu, 03 Aug 2017 05:53:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddCp7-0004Y7-E4 for emacs-orgmode@gnu.org; Thu, 03 Aug 2017 05:53:48 -0400 Received: from [195.159.176.226] (port=43500 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ddCp7-0004We-78 for emacs-orgmode@gnu.org; Thu, 03 Aug 2017 05:53:45 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1ddCoy-0008Gb-Ln for emacs-orgmode@gnu.org; Thu, 03 Aug 2017 11:53:36 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Thierry Banel writes: > Alternatively you have the orgtbl-aggregate package available on Melpa. > > #+BEGIN: aggregate :table "myvalues" :cols "min(Values) max(Values) > mean(Values)" > > | min(Values) | max(Values) | mean(Values) | > |-------------+-------------+--------------| > | 2 | 7 | 4.5 | Wow, that's very cool! Had no idea about that package. Karl, if that doesn't work for you, you might look at the org-table-to-lisp function. Here's an example of a function that uses it to sum columns in the current region: #+BEGIN_SRC elisp (defun org-fitness-sum-table-lines () "Sum each numeric column in table lines touched by the region." (interactive) (org-with-wide-buffer (let* ( ;; Add empty column because (org-table-get-specials) leaves the empty one out, which throws off the indices (header (cons nil (org-table-column-names))) (start (save-excursion (goto-line (line-number-at-pos (region-beginning))) (line-beginning-position))) (end (save-excursion (goto-line (line-number-at-pos (region-end))) (line-end-position))) (lines (buffer-substring-no-properties start end)) (table (--remove (equal 'hline it) (org-table-to-lisp lines))) (indices (cdr ; Drop index representing first column, which is always empty (butlast ; Drop index representing last column, which is comments (-find-indices (lambda (col) (or (string= col "") (string= col "0") (string= col "0.0") (string= col "0.00") (< 0 (string-to-number col)))) (car table))))) (sums (cl-loop for i in indices collect (-reduce '+ (-map 'string-to-number (-select-column i table))))) (result (-zip (-select-by-indices indices header) sums))) (org-fitness-display-values result :prefix "Lines: ")))) #+END_SRC