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 <we...@gmx.li>


Reply via email to