From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Field coordinates and moving averages Date: Tue, 15 Nov 2011 10:52:59 -0500 Message-ID: <26090.1321372379@alphaville.dokosmarshall.org> References: <878vnhpfw5.fsf@bnbeckwith.com> Reply-To: nicholas.dokos@hp.com Return-path: Received: from eggs.gnu.org ([140.186.70.92]:35198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQLJn-0005Ii-Uh for emacs-orgmode@gnu.org; Tue, 15 Nov 2011 10:53:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RQLJm-0006br-Tj for emacs-orgmode@gnu.org; Tue, 15 Nov 2011 10:53:03 -0500 Received: from g6t0185.atlanta.hp.com ([15.193.32.62]:3253) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQLJm-0006bc-Ot for emacs-orgmode@gnu.org; Tue, 15 Nov 2011 10:53:02 -0500 In-Reply-To: Message from Benjamin Beckwith of "Tue, 15 Nov 2011 10:21:40 EST." <878vnhpfw5.fsf@bnbeckwith.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Benjamin Beckwith Cc: nicholas.dokos@hp.com, emacs-orgmode@gnu.org Benjamin Beckwith wrote: > > I'm trying to create a table of periodic data and calculate a moving > average in an adjacent column. I was trying to use field coordinates, > but they do not work how I would like them to work. > > Here is what I have for a 5-day moving average: > > | Daily Data | Moving Average | > |------------+----------------| > | 10 | | > | 11 | | > | 12 | | > | 13 | | > | 14 | | > | 14 | | > | 16 | | > #+TBLFM: $2=if(@# >=7, vmean(@-5$1..@0$1),string("")); > > I expeced the if(@# >=7..) to protect the sub-clauses from executing > unless the predicate is true. However, that is not the case. When I > try to execute this formula, I receive the error: "Row descriptor -5 > used in line ### leads outside table". > > I can see how this is true if the ranges are checked for every entry. > Is there a better way for me to write this column forumla? Is this a > limitation in the field coordinates? > Try a range on the LHS: #+TBLFM: @7$2..@>$2=vmean(@-5$1..@0$1) FWIW, I avoid calc conditionals because I don't really understand how they work. E.g. you are assuming that it evals the condition and iff true, it proceeds to eval one or the other of the clauses, but the lisp error shows that that's not how it works. I prefer to deal with such problems by writing a lisp function instead. Nick