From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Moe Subject: Re: questions about table mode and spreadsheets Date: Tue, 07 Sep 2010 00:44:03 +0200 Message-ID: <4C856EB3.9060608@christianmoe.com> References: Reply-To: mail@christianmoe.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=46693 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OskPC-0007LV-LB for emacs-orgmode@gnu.org; Mon, 06 Sep 2010 18:43:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OskPB-00019g-8W for emacs-orgmode@gnu.org; Mon, 06 Sep 2010 18:43:14 -0400 Received: from mars.hitrost.net ([91.185.193.39]:29179) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OskPB-00016H-3P for emacs-orgmode@gnu.org; Mon, 06 Sep 2010 18:43:13 -0400 In-Reply-To: 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: Inquisitive Scientist Cc: emacs-orgmode@gnu.org On 9/6/10 3:38 PM, Inquisitive Scientist wrote: > 2. How do I compute the sum of a column only if a corresponding row > matches some condition? For example, how do I compute the sum of > numbers in column a for which the name in column "name" is "bar"? For > example, I should get 7 for the sum in column a in the table below: > > | name | a | b | c | > |------+---+---+---| > | foo | 1 | 2 | 3 | > | bar | 3 | 2 | 1 | > | bar | 4 | 5 | 6 | > |------+---+---+---| Here's one way: Add a new row after the first, as below. Then run C-c C-c on the formula line: | name | | a | b | c | |------+---+---+---+---| | foo | | 1 | 2 | 3 | | bar | | 3 | 2 | 1 | | bar | | 4 | 5 | 6 | |------+---+---+---+---| | | | | | | #+TBLFM: $2='(if (string= $1 "bar") 1 0):: @5$3=vsum(vmask(@I$2..@II$2,@I..@II)) It does exactly what you asked, but I don't think it will scale well... Cheers, Christian > > Thanks, > -I.S. > > > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode -- Christian Moe E-mail: mail@christianmoe.com Website: http://christianmoe.com