[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] unexpected failure on all formulas
From: |
Lawrence Mitchell |
Subject: |
Re: [O] unexpected failure on all formulas |
Date: |
Tue, 20 Sep 2011 10:15:29 +0100 |
User-agent: |
Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (gnu/linux) |
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:
@address@hidden(@address@hidden)::@address@hidden(@address@hidden)::@address@hidden'(mapconcat
'number-to-string (mode @address@hidden) ", ");N
Lawrence
--
Lawrence Mitchell <address@hidden>