From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Spreadsheet and weighted means Date: Wed, 01 Oct 2008 18:46:02 +0200 Message-ID: <87y718nu0l.fsf@selenimh.orion.org> References: <87wsh7w589.fsf@selenimh.orion.org> <9136F031-BBCD-4A80-A117-6047C5D3F777@uva.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kl4tp-00052Y-EO for emacs-orgmode@gnu.org; Wed, 01 Oct 2008 12:50:06 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kl4tn-00050V-7k for emacs-orgmode@gnu.org; Wed, 01 Oct 2008 12:50:04 -0400 Received: from [199.232.76.173] (port=50288 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kl4tm-0004zb-N7 for emacs-orgmode@gnu.org; Wed, 01 Oct 2008 12:50:02 -0400 Received: from sp604003av.neufgp.fr ([84.96.92.124]:47318 helo=neuf-infra-smtp-out-sp604003av.neufgp.fr) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Kl4tl-0003sw-HC for emacs-orgmode@gnu.org; Wed, 01 Oct 2008 12:50:01 -0400 In-Reply-To: <9136F031-BBCD-4A80-A117-6047C5D3F777@uva.nl> (Carsten Dominik's message of "Mon, 29 Sep 2008 10:43:14 +0200") 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: Carsten Dominik Cc: emacs-orgmode@gnu.org 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. Finally, I wondered if it would be useful to make it built-in as weighted means are somewhat popular in education. Anyway, thanks again. -- Nicolas Goaziou