From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lawrence Mitchell Subject: Re: unexpected failure on all formulas Date: Tue, 20 Sep 2011 10:15:29 +0100 Message-ID: <87ehzb8thq.fsf@gmx.li> References: <18072.1316499460@alphaville.dokosmarshall.org> <19773.1316507170@alphaville.dokosmarshall.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:45015) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R5wQX-0002QQ-1Z for emacs-orgmode@gnu.org; Tue, 20 Sep 2011 05:15:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R5wQT-0001Sd-LI for emacs-orgmode@gnu.org; Tue, 20 Sep 2011 05:15:40 -0400 Received: from lo.gmane.org ([80.91.229.12]:36350) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R5wQT-0001SN-BV for emacs-orgmode@gnu.org; Tue, 20 Sep 2011 05:15:37 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1R5wQS-0005ud-9u for emacs-orgmode@gnu.org; Tue, 20 Sep 2011 11:15:36 +0200 Received: from e4300lm.epcc.ed.ac.uk ([129.215.63.156]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 20 Sep 2011 11:15:36 +0200 Received: from wence by e4300lm.epcc.ed.ac.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 20 Sep 2011 11:15: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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Nick Dokos wrote: [...] > I cribbed heavily from the implementation of vmedian. Although there is > no key binding, you can even use the above in an interactive Calc > session, by entering the formula in algebraic form. I yanked the vector > twice onto the Calc stack and then entered 'vmode($) with the following > result: This does the wrong thing for bimodal lists of numbers, since the correct answer in that case is the list of modes. Here's an elisp implementation that's a bit shorter: (require 'cl) (defun mode (&rest list) (let ((ret nil) val count) (loop for n in list if (assq n ret) do (incf (cdr (assq n ret))) else do (push (cons n 1) ret)) (setq ret (sort ret (lambda (a b) (> (cdr a) (cdr b))))) (setq val (list (caar ret)) count (cdar ret)) (loop for (n . c) in (cdr ret) while (= c count) do (push n val)) val)) And here's how to use it in the proffered table: | Date Stamp | Systalic | Diastalic | Pulse | |------------------------+----------+-----------+-------| | [2011-07-19 Tue 02:26] | 138 | 92 | 74 | | [2011-07-20 Wed 04:03] | 130 | 85 | 74 | |------------------------+----------+-----------+-------| | min | 130 | 85 | 74 | | max | 138 | 92 | 74 | | mode | 138, 130 | 92, 85 | 74 | #+TBLFM: @II+1$2..@II+1$4=vmin(@I..@II)::@II+2$2..@II+2$4=vmax(@I..@II)::@II+3$2..@II+3$4='(mapconcat 'number-to-string (mode @I..@II) ", ");N Lawrence -- Lawrence Mitchell