emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Calculating percentage
@ 2017-07-15  5:06 Cecil Westerhof
  2017-07-15 14:56 ` Adonay Felipe Nogueira
  0 siblings, 1 reply; 4+ messages in thread
From: Cecil Westerhof @ 2017-07-15  5:06 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 887 bytes --]

I have implemented something in different ways. I have the following table:
|----------+------------|
|  Average | Percentage |
|----------+------------|
| 3.01E+00 |            |
| 7.31E+00 |            |
|----------+------------|
| 2.72E+01 |            |
| 4.09E+01 |            |
|----------+------------|
| 6.80E+01 |            |
| 7.07E+01 |            |
|----------+------------|
| 7.19E+01 |            |
| 9.87E+01 |            |
|----------+------------|

The average column is the runtime of the different implementations. The
last one is the original implementation.
In the percentage column I would like to have the percentage of time
compared to the original implementation. So for example the first
Percentage field should contain 3 (or 3 %).
How would I do this? It would be nice if the last Percentage field stays
empty, but that is not necessary.

-- 
Cecil Westerhof

[-- Attachment #2: Type: text/html, Size: 1488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Calculating percentage
  2017-07-15  5:06 Cecil Westerhof
@ 2017-07-15 14:56 ` Adonay Felipe Nogueira
  0 siblings, 0 replies; 4+ messages in thread
From: Adonay Felipe Nogueira @ 2017-07-15 14:56 UTC (permalink / raw)
  To: emacs-orgmode

* If you want to calculate the percentage change

Say, from [last row, first column] to [current row, first column], that
is:

( current - last_in_table ) / last_in_table

Then do either one of the following:

a. Direct answer. Go below the table and insert (without the extra spaces):

   #+TBLFM: @2$2..@>>$2=relch(@>$1, $1) * 100

b. Detailed answer. Go to any place inside the table and press C-c ',
   and insert (without the extra spaces):

    @2$2..@>>$2=relch(@>$1, $1) * 100

    "@" is row specification, "$" is column specification, ".." selects
    a range. Digits after "@" and "$" are absolute references (but as
    far as I can tell, these digits only count after the horizontal
    lines), ">" or "<" after these are relative to the last and first
    (of the entire table, this as far as I can tell also includes rows
    of horizontal lines), respectively.

The advantages of using (b) over (a) are:

- You have a split, friendly --- and probably highlighted --- view of
  what you're doing.

- Multiple formulas can be inserted simply by breaking a line. In the
  case of (a), you would have to manually insert "::" for each new
  formula for a given cell or cell range. Note that inserting multiple
  "#+TBLFM:" in order to apply multiple formulas to the same table at
  once isn't right, only the first "#+TBLFM" is evaluated.

** Example

--8<---------------cut here---------------start------------->8---
|----------+------------|
|  Average | Percentage |
|----------+------------|
| 3.01E+00 | -96.950355 |
| 7.31E+00 | -92.593718 |
|----------+------------|
| 2.72E+01 | -72.441743 |
| 4.09E+01 | -58.561297 |
|----------+------------|
| 6.80E+01 | -31.104357 |
| 7.07E+01 | -28.368794 |
|----------+------------|
| 7.19E+01 | -27.152989 |
| 9.87E+01 |            |
|----------+------------|
#+TBLFM: @2$2..@>>$2=relch(@>$1, $1) * 100
--8<---------------cut here---------------end--------------->8---

* If you want to calculate the percentage of the new value compared to
  the old value

Such as:

current / last_in_table

Then use:

$1 / @>$1

Instead of:

relch(@>$1, $1)

** Example

--8<---------------cut here---------------start------------->8---
|----------+------------|
|  Average | Percentage |
|----------+------------|
| 3.01E+00 |  3.0496454 |
| 7.31E+00 |  7.4062817 |
|----------+------------|
| 2.72E+01 |  27.558257 |
| 4.09E+01 |  41.438703 |
|----------+------------|
| 6.80E+01 |  68.895643 |
| 7.07E+01 |  71.631206 |
|----------+------------|
| 7.19E+01 |  72.847011 |
| 9.87E+01 |            |
|----------+------------|
#+TBLFM: @2$2..@>>$2=($1 / @>$1) * 100
--8<---------------cut here---------------end--------------->8---

-- 
- [[https://libreplanet.org/wiki/User:Adfeno]]
- Palestrante e consultor sobre /software/ livre (não confundir com
  gratis).
- "WhatsApp"? Ele não é livre, por isso não uso. Iguais a ele prefiro
  GNU Ring, ou Tox. Quer outras formas de contato? Adicione o vCard
  que está no endereço acima aos teus contatos.
- Pretende me enviar arquivos .doc, .ppt, .cdr, ou .mp3? OK, eu
  aceito, mas não repasso. Entrego apenas em formatos favoráveis ao
  /software/ livre. Favor entrar em contato em caso de dúvida.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Calculating percentage
       [not found] <e59c1668074b42d6855ee636cc8ad3ec@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
@ 2017-07-16 18:32 ` Eric S Fraga
  2017-07-17  8:22   ` Cecil Westerhof
  0 siblings, 1 reply; 4+ messages in thread
From: Eric S Fraga @ 2017-07-16 18:32 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 93 bytes --]

See attached.
HTH,
eric

-- 
: Eric S Fraga via Emacs 26.0.50, Org release_9.0.9-573-g09e612

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: t.org --]
[-- Type: text/x-org, Size: 417 bytes --]

|----------+------------|
|  Average | Percentage |
|----------+------------|
| 3.01E+00 |         3. |
| 7.31E+00 |         7. |
|----------+------------|
| 2.72E+01 |        28. |
| 4.09E+01 |        41. |
|----------+------------|
| 6.80E+01 |        69. |
| 7.07E+01 |        72. |
|----------+------------|
| 7.19E+01 |        73. |
| 9.87E+01 |       100. |
|----------+------------|
#+TBLFM: $2=100*$1/@>$1;f0

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Calculating percentage
  2017-07-16 18:32 ` Calculating percentage Eric S Fraga
@ 2017-07-17  8:22   ` Cecil Westerhof
  0 siblings, 0 replies; 4+ messages in thread
From: Cecil Westerhof @ 2017-07-17  8:22 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 141 bytes --]

2017-07-16 20:32 GMT+02:00 Eric S Fraga <e.fraga@ucl.ac.uk>:

> See attached.
>

​Works perfect thanks.​


-- 
Cecil Westerhof

[-- Attachment #2: Type: text/html, Size: 592 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-07-17  8:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <e59c1668074b42d6855ee636cc8ad3ec@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2017-07-16 18:32 ` Calculating percentage Eric S Fraga
2017-07-17  8:22   ` Cecil Westerhof
2017-07-15  5:06 Cecil Westerhof
2017-07-15 14:56 ` Adonay Felipe Nogueira

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).