From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: Spreadsheet and weighted means Date: Wed, 1 Oct 2008 21:26:37 +0200 Message-ID: References: <87wsh7w589.fsf@selenimh.orion.org> <9136F031-BBCD-4A80-A117-6047C5D3F777@uva.nl> <87y718nu0l.fsf@selenimh.orion.org> Mime-Version: 1.0 (Apple Message framework v929.2) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kl7LU-0004aS-Hv for emacs-orgmode@gnu.org; Wed, 01 Oct 2008 15:26:48 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kl7LT-0004a7-Sv for emacs-orgmode@gnu.org; Wed, 01 Oct 2008 15:26:48 -0400 Received: from [199.232.76.173] (port=39670 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kl7LT-0004a4-Mm for emacs-orgmode@gnu.org; Wed, 01 Oct 2008 15:26:47 -0400 Received: from paard.ic.uva.nl ([145.18.40.182]:49690) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Kl7LT-0005n4-6b for emacs-orgmode@gnu.org; Wed, 01 Oct 2008 15:26:47 -0400 In-Reply-To: <87y718nu0l.fsf@selenimh.orion.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nicolas Goaziou Cc: emacs-orgmode@gnu.org Hi Nicolas, On Oct 1, 2008, at 6:46 PM, Nicolas Goaziou wrote: > Carsten Dominik 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