emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Michael Brand <michael.ch.brand@gmail.com>
To: Cecil Westerhof <cldwesterhof@gmail.com>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: Difference between two rows
Date: Sun, 1 Jun 2014 15:18:10 +0200	[thread overview]
Message-ID: <CALn3zoiRB8E2UaCstKqKvnKx7ENh1nq25=JgPF9uK7PGjG5_HQ@mail.gmail.com> (raw)
In-Reply-To: <CAG-LmmCcwrb04MCyLxQT6objgV0AyJ+gRKcGC3LvX5M820mSaA@mail.gmail.com>

Hi Cecil

On Sun, Jun 1, 2014 at 2:24 PM, Cecil Westerhof <cldwesterhof@gmail.com> wrote:
> But what if I would want to know the
> difference between the previous filled one, divided by the distance?
>
> For example:
> |-------+------------|
> | value | difference |
> |-------+------------|
> |    12 |            |
> |    15 |          3 |
> |       |            |
> |    83 |         34 |
> |       |            |
> |       |            |
> |       |            |
> |    87 |          1 |
> |       |            |
> |       |            |
> |       |            |
> |    85 |       -0.5 |
> |       |            |
> |-------+------------|

More as a demonstration of what Calc can do, divided up into some
intermediate steps:

|-------+---------------------------------------------------------|
| value | difference                                              |
|-------+---------------------------------------------------------|
|    12 |                                                         |
|    15 | [15, 12]                                                |
|       |                                                         |
|    83 | [83, nan, 15, 12]                                       |
|       |                                                         |
|       |                                                         |
|       |                                                         |
|    87 | [87, nan, nan, nan, 83, nan, 15, 12]                    |
|       |                                                         |
|       |                                                         |
|       |                                                         |
|    85 | [85, nan, nan, nan, 87, nan, nan, nan, 83, nan, 15, 12] |
|       |                                                         |
|-------+---------------------------------------------------------|
#+TBLFM: $2 = if(vlen(@-I$1..@0$1) == 1 || "$1" == "nan", string(""),
rev(@-I$1..@0$1)); E

|-------+----------------------------------------------------|
| value | difference                                         |
|-------+----------------------------------------------------|
|    12 |                                                    |
|    15 | [0, 0]                                             |
|       |                                                    |
|    83 | [0, nan, 0, 0]                                     |
|       |                                                    |
|       |                                                    |
|       |                                                    |
|    87 | [0, nan, nan, nan, 0, nan, 0, 0]                   |
|       |                                                    |
|       |                                                    |
|       |                                                    |
|    85 | [0, nan, nan, nan, 0, nan, nan, nan, 0, nan, 0, 0] |
|       |                                                    |
|-------+----------------------------------------------------|
#+TBLFM: $2 = if(vlen(@-I$1..@0$1) == 1 || "$1" == "nan", string(""),
0 * rev(@-I$1..@0$1)); E

Distance to previous element:

|-------+------------|
| value | difference |
|-------+------------|
|    12 |            |
|    15 |          1 |
|       |            |
|    83 |          2 |
|       |            |
|       |            |
|       |            |
|    87 |          4 |
|       |            |
|       |            |
|       |            |
|    85 |          4 |
|       |            |
|-------+------------|
#+TBLFM: $2 = if(vlen(@-I$1..@0$1) == 1 || "$1" == "nan", string(""),
find(0 * rev(@-I$1..@0$1), 0, 2) - 1); E

Previous element:

|-------+------------|
| value | difference |
|-------+------------|
|    12 |            |
|    15 |         12 |
|       |            |
|    83 |         15 |
|       |            |
|       |            |
|       |            |
|    87 |         83 |
|       |            |
|       |            |
|       |            |
|    85 |         87 |
|       |            |
|-------+------------|
#+TBLFM: $2 = if(vlen(@-I$1..@0$1) == 1 || "$1" == "nan", string(""),
subscr(rev(@-I$1..@0$1), find(0 * rev(@-I$1..@0$1), 0, 2)); E

Combined:

|-------+------------|
| value | difference |
|-------+------------|
|    12 |            |
|    15 |          3 |
|       |            |
|    83 |         34 |
|       |            |
|       |            |
|       |            |
|    87 |          1 |
|       |            |
|       |            |
|       |            |
|    85 |       -0.5 |
|       |            |
|-------+------------|
#+TBLFM: $2 = if(vlen(@-I$1..@0$1) == 1 || "$1" == "nan", string(""),
($1 - subscr(rev(@-I$1..@0$1), find(0 * rev(@-I$1..@0$1), 0, 2))) /
(find(0 * rev(@-I$1..@0$1), 0, 2) - 1)); E

For many here on the list it would probably be easier and more
interesting to write a TBLFM in Lisp.

Michael

  reply	other threads:[~2014-06-01 13:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-01 11:38 Difference between two rows Cecil Westerhof
2014-06-01 11:57 ` Michael Brand
2014-06-01 12:24   ` Cecil Westerhof
2014-06-01 13:18     ` Michael Brand [this message]
2014-06-01 14:12       ` Cecil Westerhof
2014-06-01 17:57 ` Thierry Banel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALn3zoiRB8E2UaCstKqKvnKx7ENh1nq25=JgPF9uK7PGjG5_HQ@mail.gmail.com' \
    --to=michael.ch.brand@gmail.com \
    --cc=cldwesterhof@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).