From: Carsten Dominik <dominik@uva.nl>
To: Nicolas Goaziou <n.goaziou@neuf.fr>
Cc: emacs-orgmode@gnu.org
Subject: Re: Spreadsheet and weighted means
Date: Wed, 1 Oct 2008 21:26:37 +0200 [thread overview]
Message-ID: <CDC9DB57-9952-4008-8363-69CF0467E8FB@uva.nl> (raw)
In-Reply-To: <87y718nu0l.fsf@selenimh.orion.org>
Hi Nicolas,
On Oct 1, 2008, at 6:46 PM, Nicolas Goaziou wrote:
> Carsten Dominik <dominik@uva.nl> writes:
>
> Hello,
>
>> Hi Nicolas, there s no builtin way to deal with this, in particular
>> with the fact that you want to treat empty fields as non-existing,
>> and
>> therefore also to ignore the corresponding weight.
>>
>> You cou write a Lisp function to do this, though:
>>
>> (defun my-wmean (values weights)
>> (let ((vsum 0) (wsum 0))
>> (while (and values weights)
>> (setq v (pop values) w (pop weights))
>> (unless (equal "" v)
>> (setq vsum (+ vsum (* (string-to-number w) (string-to-number
>> v)))
>> wsum (+ wsum (string-to-number w)))))
>> (/ vsum wsum)))
>
> Well, thank you very much: it does the job.
>
> I don't want to be picky but I'll investigate on a way to have an
> empty
> string instead of a sorry 0 whenever a student hasn't sat for any
> exam.
Well, you can do this by leaving the formatting to the function
instead of the formula under the table:
(defun my-wmean (values weights)
(let ((vsum 0) (wsum 0))
(while (and values weights)
(setq v (pop values) w (pop weights))
(unless (equal "" v)
(setq vsum (+ vsum (* (string-to-number w) (string-to-number v)))
wsum (+ wsum (string-to-number w)))))
(if (= vsum 0) "" (format "%.1f" (/ vsum wsum)))))
The you could use this as your equation:
| | Coeff. | 0.2 | 0.5 | 1 |
|-----------+--------+--------+--------+--------|
| Name | | Test 1 | Test 2 | Test 3 |
|-----------+--------+--------+--------+--------|
| Student A | 10.0 | 15 | 12 | 8 |
| Student B | 12.7 | | 16 | 11 |
| Student C | | | | |
#+TBLFM: $2='(my-wmean '($3..$5) '(@1$3..@1$5));E
>
> Finally, I wondered if it would be useful to make it built-in as
> weighted means are somewhat popular in education.
Well, I could do that, of course. But which version of this
function? What ouput etc?
I guess this would then be the original version, which returns a
number, and which returns 0 if the student has done absolutely
nothing....
- Carsten
next prev parent reply other threads:[~2008-10-01 19:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-20 7:00 Spreadsheet and weighted means Nicolas Goaziou
2008-09-29 8:43 ` Carsten Dominik
2008-09-29 8:44 ` Carsten Dominik
2008-10-01 16:46 ` Nicolas Goaziou
2008-10-01 19:26 ` Carsten Dominik [this message]
2008-10-01 19:45 ` Embedded elisp formulas, was: " Eric Schulte
2008-10-01 20:29 ` Paul R
2008-10-02 0:03 ` Eric Schulte
2008-10-02 11:44 ` Carsten Dominik
2008-10-08 23:12 ` ANN: org-eval-light.el was: " Eric Schulte
2008-11-06 1:19 ` Eric Schulte
2008-11-09 7:02 ` Carsten Dominik
2008-11-10 19:51 ` Daniel Clemente
2008-10-04 8:49 ` Nicolas Goaziou
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CDC9DB57-9952-4008-8363-69CF0467E8FB@uva.nl \
--to=dominik@uva.nl \
--cc=emacs-orgmode@gnu.org \
--cc=n.goaziou@neuf.fr \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.