emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Using constants in columns
@ 2015-10-16 12:39 Guido Van Hoecke
  2015-10-16 13:48 ` Eric S Fraga
  0 siblings, 1 reply; 9+ messages in thread
From: Guido Van Hoecke @ 2015-10-16 12:39 UTC (permalink / raw)
  To: orgmode

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

Hi,

Is there a way to use a constant directly in a table column?
I need to have a table where one of the columns can have one out of three
possible values and wanted to use constants for this.
From the following minimal example it appears that constants are only
possible in formulas, or am I missing something?

#+CONSTANTS: vat=1.21
| 12.34 | $vat | #ERROR | 14.9314 |
#+TBLFM: $3=$1*$2::$4=$1*$vat

Using the $vat constant directly from the content of column 3 produces an
error, using it from a formula works fine.

If this is the way it is, I'll have to write a formula for each row of the
column, that'd be a real pitty...

Please advise

TIA, Guido

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

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

* Re: Using constants in columns
  2015-10-16 12:39 Using constants in columns Guido Van Hoecke
@ 2015-10-16 13:48 ` Eric S Fraga
  2015-10-16 14:38   ` Guido Van Hoecke
  0 siblings, 1 reply; 9+ messages in thread
From: Eric S Fraga @ 2015-10-16 13:48 UTC (permalink / raw)
  To: Guido Van Hoecke; +Cc: orgmode

On Friday, 16 Oct 2015 at 14:39, Guido Van Hoecke wrote:
> Hi,
>
> Is there a way to use a constant directly in a table column?
> I need to have a table where one of the columns can have one out of three
> possible values and wanted to use constants for this.
> From the following minimal example it appears that constants are only
> possible in formulas, or am I missing something?
>
> #+CONSTANTS: vat=1.21
> | 12.34 | $vat | #ERROR | 14.9314 |
>
> #+TBLFM: $3=$1*$2::$4=$1*$vat
>
> Using the $vat constant directly from the content of column 3 produces an
> error, using it from a formula works fine.
>
> If this is the way it is, I'll have to write a formula for each row of the
> column, that'd be a real pitty...

Maybe not pretty but for a small number of alternatives, you could do:

#+begin_src org
  ,#+constants: vat=[1.15,1.21,1.40]
  | amount | vat1 | vat2 | vat3 |   total |
  |--------+------+------+------+---------|
  |  12.34 |    1 |    0 |    0 |  14.191 |
  |  56.78 |    0 |    1 |    0 | 68.7038 |
  ,#+TBLFM: $5=$1*vsum($2..$4*$vat)
#+end_src

alternatively, you could have an integer value in the VAT column and use
that to index the vector of VAT values?
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3.2-161-gd2ac25

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

* Re: Using constants in columns
  2015-10-16 13:48 ` Eric S Fraga
@ 2015-10-16 14:38   ` Guido Van Hoecke
  2015-10-16 14:59     ` Eric S Fraga
  0 siblings, 1 reply; 9+ messages in thread
From: Guido Van Hoecke @ 2015-10-16 14:38 UTC (permalink / raw)
  To: orgmode, Eric S Fraga

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

Hi Eric,

Thanks for the suggestions, I'll go for the integer value used as an index
:)

Have a nice weekend,


Guido

On 16 October 2015 at 15:48, Eric S Fraga <e.fraga@ucl.ac.uk> wrote:

> On Friday, 16 Oct 2015 at 14:39, Guido Van Hoecke wrote:
> > Hi,
> >
> > Is there a way to use a constant directly in a table column?
> > I need to have a table where one of the columns can have one out of three
> > possible values and wanted to use constants for this.
> > From the following minimal example it appears that constants are only
> > possible in formulas, or am I missing something?
> >
> > #+CONSTANTS: vat=1.21
> > | 12.34 | $vat | #ERROR | 14.9314 |
> >
> > #+TBLFM: $3=$1*$2::$4=$1*$vat
> >
> > Using the $vat constant directly from the content of column 3 produces an
> > error, using it from a formula works fine.
> >
> > If this is the way it is, I'll have to write a formula for each row of
> the
> > column, that'd be a real pitty...
>
> Maybe not pretty but for a small number of alternatives, you could do:
>
> #+begin_src org
>   ,#+constants: vat=[1.15,1.21,1.40]
>   | amount | vat1 | vat2 | vat3 |   total |
>   |--------+------+------+------+---------|
>   |  12.34 |    1 |    0 |    0 |  14.191 |
>   |  56.78 |    0 |    1 |    0 | 68.7038 |
>   ,#+TBLFM: $5=$1*vsum($2..$4*$vat)
> #+end_src
>
> alternatively, you could have an integer value in the VAT column and use
> that to index the vector of VAT values?
> --
> : Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3.2-161-gd2ac25
>

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

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

* Re: Using constants in columns
  2015-10-16 14:38   ` Guido Van Hoecke
@ 2015-10-16 14:59     ` Eric S Fraga
  2015-10-17 11:47       ` Guido Van Hoecke
  0 siblings, 1 reply; 9+ messages in thread
From: Eric S Fraga @ 2015-10-16 14:59 UTC (permalink / raw)
  To: Guido Van Hoecke; +Cc: orgmode

On Friday, 16 Oct 2015 at 16:38, Guido Van Hoecke wrote:
> Hi Eric,
>
> Thanks for the suggestions, I'll go for the integer value used as an index

and please post the index solution for the record?
thanks,
eric
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3.2-161-gd2ac25

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

* Re: Using constants in columns
  2015-10-16 14:59     ` Eric S Fraga
@ 2015-10-17 11:47       ` Guido Van Hoecke
  2015-10-17 18:00         ` Michael Brand
  0 siblings, 1 reply; 9+ messages in thread
From: Guido Van Hoecke @ 2015-10-17 11:47 UTC (permalink / raw)
  To: orgmode, Eric S Fraga

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

On 16 October 2015 at 16:59, Eric S Fraga <e.fraga@ucl.ac.uk> wrote:

> On Friday, 16 Oct 2015 at 16:38, Guido Van Hoecke wrote:
> > Hi Eric,
> >
> > Thanks for the suggestions, I'll go for the integer value used as an
> index
>
> and please post the index solution for the record?
>

I have not found a way to specify the vector in a constant.
Elisp
​ ​
​needs arrays with space rather than comma as separator, and I can't
​​
find how
​to specify such arrays as constants.

Specifying the vector directly in the formula does work:

#+begin_src org
    |      1 |     0 |    10 |
    |      2 |     1 |   400 |
    |      3 |     2 |  9000 |
  ,#+TBLFM: $3='(* $1 (aref [10 200 3000] $2));N
#+end_src

That is ok if the vector is only to be used in one single formula.

A nicer way is to specify the vector values in named tables and to
reference them 'remotely':

#+begin_src org
  ,#+name: v1
  |10|

  ,#+name: v2
  |200|

  ,#+name: v3
  |3000|


  ,#+name: the table to be computed
  | 5 | v1 |   50 |
  | 2 | v2 |  400 |
  | 3 | v3 | 9000 |
  ,#+TBLFM: $3= $1 * remote($2, @1$1);N
#+end_src

With this solution the values only need to be specified once and can
be used where- and whenever needed.

-- 
Guido

===  ALL USERS PLEASE NOTE  ========================

A new system, the CIRCULATORY system, has been added.

The long-experimental CIRCULATORY system has been released to users.  The
Lisp Machine uses Type B fluid, the L machine uses Type A fluid.  When the
switch to Common Lisp occurs both machines will, of course, be Type O.
Please check fluid level by using the DIP stick which is located in the
back of VMI monitors.  Unchecked low fluid levels can cause poor paging
performance.

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

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

* Re: Using constants in columns
  2015-10-17 11:47       ` Guido Van Hoecke
@ 2015-10-17 18:00         ` Michael Brand
  2015-10-17 20:27           ` Guido Van Hoecke
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Brand @ 2015-10-17 18:00 UTC (permalink / raw)
  To: Guido Van Hoecke; +Cc: orgmode

Hi Guido

On Sat, Oct 17, 2015 at 1:47 PM, Guido Van Hoecke <guivho@gmail.com> wrote:
> I have not found a way to specify the vector in a constant.

You can access the elements of the vector constant suggested by Eric
with Calc's subscript function:

#+CONSTANTS: vat=[1.15,1.21,1.40]

| Amount | VAT |  Total |
|--------+-----+--------|
|    100 |   1 | 115.00 |
|    100 |   2 | 121.00 |
#+TBLFM: $3 = $1 * subscr($vat, $2); %.2f

Michael

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

* Re: Using constants in columns
  2015-10-17 18:00         ` Michael Brand
@ 2015-10-17 20:27           ` Guido Van Hoecke
  2015-10-19  6:12             ` Eric S Fraga
  0 siblings, 1 reply; 9+ messages in thread
From: Guido Van Hoecke @ 2015-10-17 20:27 UTC (permalink / raw)
  To: Michael Brand; +Cc: orgmode

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

On 17 October 2015 at 20:00, Michael Brand <michael.ch.brand@gmail.com>
wrote:

> Hi Guido
>
> On Sat, Oct 17, 2015 at 1:47 PM, Guido Van Hoecke <guivho@gmail.com>
> wrote:
> > I have not found a way to specify the vector in a constant.
>
> You can access the elements of the vector constant suggested by Eric
> with Calc's subscript function:
>
> #+CONSTANTS: vat=[1.15,1.21,1.40]
>
> | Amount | VAT |  Total |
> |--------+-----+--------|
> |    100 |   1 | 115.00 |
> |    100 |   2 | 121.00 |
> #+TBLFM: $3 = $1 * subscr($vat, $2); %.2f
>
> ​Thanks, Michael!

I really should study the calc manual ;)

Guido​

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

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

* Re: Using constants in columns
  2015-10-17 20:27           ` Guido Van Hoecke
@ 2015-10-19  6:12             ` Eric S Fraga
  2015-10-19  7:13               ` Guido Van Hoecke
  0 siblings, 1 reply; 9+ messages in thread
From: Eric S Fraga @ 2015-10-19  6:12 UTC (permalink / raw)
  To: Guido Van Hoecke; +Cc: Michael Brand, orgmode

On Saturday, 17 Oct 2015 at 22:27, Guido Van Hoecke wrote:

[...]

> I really should study the calc manual ;)

The last time I delved into the calc manual, I didn't resurface for
three days ;-)

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.5.1, Org release_8.3.2-164-g50a182

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

* Re: Using constants in columns
  2015-10-19  6:12             ` Eric S Fraga
@ 2015-10-19  7:13               ` Guido Van Hoecke
  0 siblings, 0 replies; 9+ messages in thread
From: Guido Van Hoecke @ 2015-10-19  7:13 UTC (permalink / raw)
  To: Michael Brand, orgmode, Eric S Fraga

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

On 19 October 2015 at 08:12, Eric S Fraga <e.fraga@ucl.ac.uk> wrote:

> On Saturday, 17 Oct 2015 at 22:27, Guido Van Hoecke wrote:
>
> [...]
>
> > I really should study the calc manual ;)
>
> The last time I delved into the calc manual, I didn't resurface for
> three days ;-)


​:-
​)​

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

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

end of thread, other threads:[~2015-10-19  7:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-16 12:39 Using constants in columns Guido Van Hoecke
2015-10-16 13:48 ` Eric S Fraga
2015-10-16 14:38   ` Guido Van Hoecke
2015-10-16 14:59     ` Eric S Fraga
2015-10-17 11:47       ` Guido Van Hoecke
2015-10-17 18:00         ` Michael Brand
2015-10-17 20:27           ` Guido Van Hoecke
2015-10-19  6:12             ` Eric S Fraga
2015-10-19  7:13               ` Guido Van Hoecke

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