emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Alignment of numbers in tables with `nan' in some table cells
@ 2007-08-12 20:33 Christian Schlauer
  2007-08-14 13:09 ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Schlauer @ 2007-08-12 20:33 UTC (permalink / raw)
  To: emacs-orgmode

Hello Carsten, hello list!

This is about alignment of numbers in tables. Say I have three columns
with data (the first three columns). Then I do calculations on them
(the last two columns).

Columns 2 and 3 are "complete" -- I have data in each field, so there
is always some useful result in column 4, as $4=$2-$3. But column 5 is
$5=$1-$4, and in column 1 there are some empty fields where data are
missing, unfortunately. That leads to a negative value of -6 in line
3, column 5:

| data 1 | data 2 | data 3 | result 1 | result 2 |
|--------+--------+--------+----------+----------|
|     23 |     25 |     17 |        8 |       15 |
|        |     24 |     18 |        6 |       -6 |
#+TBLFM: $4=$2-$3::$5=$1-$4

Now, a negative value doesn't make sense in my real table. So instead
of printing a nonsensical value, I'd prefer something else there. I
remembered that MATLAB has `NaN', and Calc has that, too: `nan', see
(info "(calc)Infinities"). So I put `nan' in line 3, column 1, and
recalculate the above table:

| data 1 | data 2 | data 3 | result 1 | result 2 |
|--------+--------+--------+----------+----------|
| 23     |     25 |     17 |        8 | 15       |
| nan    |     24 |     18 |        6 | nan      |
#+TBLFM: $4=$2-$3::$5=$1-$4

It's almost perfect! It is clear that a result for column 5 in line 3
does not exist as there are no data in column 1 of that line. The only
thing that is not perfect is that the alignment in columns 1 and 5 is
messed up due to `nan'.

Could this be fixed?

Regards,
-- 
Christian Schlauer

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

* Re: Alignment of numbers in tables with `nan' in some table cells
  2007-08-12 20:33 Alignment of numbers in tables with `nan' in some table cells Christian Schlauer
@ 2007-08-14 13:09 ` Carsten Dominik
  2007-08-18  7:50   ` Christian Schlauer
  0 siblings, 1 reply; 4+ messages in thread
From: Carsten Dominik @ 2007-08-14 13:09 UTC (permalink / raw)
  To: cs-usenet; +Cc: emacs-orgmode

Hi Christian,


On Aug 12, 2007, at 22:33, Christian Schlauer wrote:
>
> | data 1 | data 2 | data 3 | result 1 | result 2 |
> |--------+--------+--------+----------+----------|
> |     23 |     25 |     17 |        8 |       15 |
> |        |     24 |     18 |        6 |       -6 |
> #+TBLFM: $4=$2-$3::$5=$1-$4
>
> Now, a negative value doesn't make sense in my real table. So instead
> of printing a nonsensical value, I'd prefer something else there. I
> remembered that MATLAB has `NaN', and Calc has that, too: `nan', see
> (info "(calc)Infinities"). So I put `nan' in line 3, column 1, and
> recalculate the above table:
>
> | data 1 | data 2 | data 3 | result 1 | result 2 |
> |--------+--------+--------+----------+----------|
> | 23     |     25 |     17 |        8 | 15       |
> | nan    |     24 |     18 |        6 | nan      |
> #+TBLFM: $4=$2-$3::$5=$1-$4
>
> It's almost perfect! It is clear that a result for column 5 in line 3
> does not exist as there are no data in column 1 of that line. The only
> thing that is not perfect is that the alignment in columns 1 and 5 is
> messed up due to `nan'.
>
> Could this be fixed?

I like that little trick with nan, it is a nice demonstration the
the full symbolic capabilities of Calc are still present in
Org-mode tables.

The table editor automatically chooses the alignment of a column,
based on the content of the column.  There are two customization
variables involved in tuning this behavior:

,----[ C-h v org-table-number-regexp RET ]
| org-table-number-regexp is a variable defined in `org.el'.
| Its value is
|  
"^\\([<>]?[-+^.0-9]*[0-9][-+^.0-9eEdDx()%:]*\\|\\(0[xX]\\)[0-9a-fA- 
F]+\\)$"
|
|
| Documentation:
| Regular expression for recognizing numbers in table columns.
| If a table column contains mostly numbers, it will be aligned to the
| right.  If not, it will be aligned to the left.
|
| The default value of this option is a regular expression which allows
| anything which looks remotely like a number as used in scientific
| context.  For example, all of the following will be considered a
| number:
|     12    12.2    2.4e-08    2x10^12    4.034+-0.02    2.7(10)  >3.5
|
| Other options offered by the customize interface are more restrictive.
`---

,----[ C-h v org-table-number-fraction RET ]
| org-table-number-fraction is a variable defined in `org.el'.
| Its value is 0.5
|
|
| Documentation:
| Fraction of numbers in a column required to make the column align  
right.
| In a column all non-white fields are considered.  If at least this
| fraction of fields is matched by `org-table-number-fraction',
| alignment to the right border applies.
`---

So you can either lower the threshold value in  
`org-table-number-fraction',
or you can modify the regular expression so that it will interpret nan  
as a
number.

I will make the default regexp swallow nan.

- Carsten

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

* Re: Alignment of numbers in tables with `nan' in some table cells
  2007-08-14 13:09 ` Carsten Dominik
@ 2007-08-18  7:50   ` Christian Schlauer
  2007-08-20  5:42     ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Schlauer @ 2007-08-18  7:50 UTC (permalink / raw)
  To: emacs-orgmode

Carsten Dominik <dominik@science.uva.nl> writes:

[...]

> The table editor automatically chooses the alignment of a column,
> based on the content of the column.  There are two customization
> variables involved in tuning this behavior:

[...]

I am often surprised how many things one can customize -- I didn't
expect this one to be customizable, for example:

> ,----[ C-h v org-table-number-fraction RET ]

[...]

> I will make the default regexp swallow nan.

Thank you! I don't want to touch that regexp myself. :-)
-- 
Christian Schlauer

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

* Re: Re: Alignment of numbers in tables with `nan' in some table cells
  2007-08-18  7:50   ` Christian Schlauer
@ 2007-08-20  5:42     ` Carsten Dominik
  0 siblings, 0 replies; 4+ messages in thread
From: Carsten Dominik @ 2007-08-20  5:42 UTC (permalink / raw)
  To: cs-usenet; +Cc: emacs-orgmode


On Aug 18, 2007, at 9:50, Christian Schlauer wrote:

> Carsten Dominik <dominik@science.uva.nl> writes:
>
> [...]
>
>> The table editor automatically chooses the alignment of a column,
>> based on the content of the column.  There are two customization
>> variables involved in tuning this behavior:
>
> [...]
>
> I am often surprised how many things one can customize -- I didn't
> expect this one to be customizable, for example:
>
>> ,----[ C-h v org-table-number-fraction RET ]
>
> [...]
>
>> I will make the default regexp swallow nan.
>
> Thank you! I don't want to touch that regexp myself. :-)

:-)  It is reasonably complex, yes.

- Carsten

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

end of thread, other threads:[~2007-08-20  5:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-12 20:33 Alignment of numbers in tables with `nan' in some table cells Christian Schlauer
2007-08-14 13:09 ` Carsten Dominik
2007-08-18  7:50   ` Christian Schlauer
2007-08-20  5:42     ` Carsten Dominik

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