On Sep 29, 2008, at 10:43 AM, Carsten Dominik wrote:
On Sep 20, 2008, at 9:00 AM, Nicolas Goaziou wrote:
Hello,
I stumbled upon this problem : I'd like to compute the weighted
mean of
some values, even though cells might be empty. In fact, I'm aiming at
something like this :
| | Coeff. | 0.2 | 0.5 | 1 |
|-----------+--------+--------+--------+--------|
| Name | Mean | Test 1 | Test 2 | Test 3 |
|-----------+--------+--------+--------+--------|
| Student A | 10 | 15 | 12 | 8 |
| Student B | 12 | | 16 | 10 |
where 10=(15*0.2+12*0.5+8*1)/(0.2+0.5+1) and 12=(16*0.5+10*1)/(0.5+1)
I just can't guess what has to be put in @3$2 as a column formula to
calculate those mean means… I perhaps have overlooked something
simple.
Anyway, if anyone has a clue here, I will be pleased to hear it.
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)))
The you could use this as your equation:
| | Coeff. | 0.2 | 0.5 | 1 |
|-----------+--------+--------+--------+--------|
| Name | 0 | Test 1 | Test 2 | Test 3 |
|-----------+--------+--------+--------+--------|
| Student A | 10 | 15 | 12 | 8 |
| Student B | 12 | | 16 | 10 |
#+TBLFM: $2='(wmean '($3..$5) '(@[EMAIL PROTECTED]));E%d
Typo: the function call must be `my-wmean', not just `wmean'.
- CarstenG
_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode