emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Lawrence Mitchell <wence@gmx.li>
To: emacs-orgmode@gnu.org
Subject: Re: unexpected failure on all formulas
Date: Tue, 20 Sep 2011 10:15:29 +0100	[thread overview]
Message-ID: <87ehzb8thq.fsf@gmx.li> (raw)
In-Reply-To: 19773.1316507170@alphaville.dokosmarshall.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 <wence@gmx.li>

  reply	other threads:[~2011-09-20  9:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-20  0:41 unexpected failure on all formulas Jude DaShiell
2011-09-20  6:17 ` Nick Dokos
2011-09-20  8:26   ` Nick Dokos
2011-09-20  9:15     ` Lawrence Mitchell [this message]
2011-09-20  9:29     ` Christian Moe
2011-09-20 14:59       ` Nick Dokos
2011-09-20 16:30         ` Nick Dokos
2011-09-20 20:28         ` Christian Moe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ehzb8thq.fsf@gmx.li \
    --to=wence@gmx.li \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).