Re: [O] Table filter.

2012-05-09 Thread Detlef Steuer
Fantastic!

Detlef


 Well, I have done something similar, which includes a few more operations 
 than filtering.
 It uses org-babel and comes as an org-file, which combines code and 
 documentation.
 
 Hope, this might be useful for you.
 
 with kind regards, Marc-Oliver Ihm
 
 





[O] Table filter.

2012-05-08 Thread x.piter
Hi all.
Is table filtering is implementad in org-mode?
Thanks.




Re: [O] Table filter.

2012-05-08 Thread Bastien
Hi,

x.pi...@gmail.com writes:

 Is table filtering is implementad in org-mode?

What is table filtering?

Thanks,

-- 
 Bastien



Re: [O] Table filter.

2012-05-08 Thread Petro
Bastien b...@gnu.org writes:

 Hi,

 x.pi...@gmail.com writes:

 Is table filtering is implementad in org-mode?

 What is table filtering?

 Thanks,

Sorry for not being clear.
By table filtering I mean the following:
lets say I have a table

| n | 2 | 3 | 4 | 5 | 6 |
|---+---+---+---+---+---|
| 1 | a |   |   |   |   |
| 2 | b |   |   |   |   |
| 3 | b |   |   |   |   |
| 4 | a |   |   |   |   |
| 5 | c |   |   |   |   |
| 6 | b |   |   |   |   |
| 7 | a |   |   |   |   |

I want to filter this table and get only rows where second column equal a
| n | 2 | 3 | 4 | 5 | 6 |
|---+---+---+---+---+---|
| 1 | a |   |   |   |   |
| 4 | a |   |   |   |   |
| 7 | a |   |   |   |   |

Thanks.




Re: [O] Table filter.

2012-05-08 Thread Bastien
Hi Petro,

Petro  x.pi...@gmail.com writes:

 lets say I have a table

 | n | 2 | 3 | 4 | 5 | 6 |
 |---+---+---+---+---+---|
 | 1 | a |   |   |   |   |
 | 2 | b |   |   |   |   |
 | 3 | b |   |   |   |   |
 | 4 | a |   |   |   |   |
 | 5 | c |   |   |   |   |
 | 6 | b |   |   |   |   |
 | 7 | a |   |   |   |   |

 I want to filter this table and get only rows where second column equal a
 | n | 2 | 3 | 4 | 5 | 6 |
 |---+---+---+---+---+---|
 | 1 | a |   |   |   |   |
 | 4 | a |   |   |   |   |
 | 7 | a |   |   |   |   |

Such feature does not exist for now, but I would welcome enhancements in
this direction.  Thanks for this idea,

-- 
 Bastien



Re: [O] Table filter.

2012-05-08 Thread Nick Dokos
Bastien b...@gnu.org wrote:

 Hi Petro,
 
 Petro  x.pi...@gmail.com writes:
 
  lets say I have a table
 
  | n | 2 | 3 | 4 | 5 | 6 |
  |---+---+---+---+---+---|
  | 1 | a |   |   |   |   |
  | 2 | b |   |   |   |   |
  | 3 | b |   |   |   |   |
  | 4 | a |   |   |   |   |
  | 5 | c |   |   |   |   |
  | 6 | b |   |   |   |   |
  | 7 | a |   |   |   |   |
 
  I want to filter this table and get only rows where second column equal a
  | n | 2 | 3 | 4 | 5 | 6 |
  |---+---+---+---+---+---|
  | 1 | a |   |   |   |   |
  | 4 | a |   |   |   |   |
  | 7 | a |   |   |   |   |
 
 Such feature does not exist for now, but I would welcome enhancements in
 this direction.  Thanks for this idea,
 

You can get most of the way there with babel, as long as you don't insist
on modifying the table in place. Something like this e.g. using python 2.x:

--8---cut here---start-8---
#+BEGIN_SRC elisp
(setq org-babel-min-lines-for-block-output 0)
#+END_SRC

#+RESULTS:
#+begin_example
0
#+end_example

The above setting is just to force an example block. The default value
(10) produces colon-demarcated results.


#+name: orig
| n | 2 | 3 | 4 | 5 | 6 |
|---+---+---+---+---+---|
| 1 | a |   |   |   |   |
| 2 | b |   |   |   |   |
| 3 | b |   |   |   |   |
| 4 | a |   |   |   |   |
| 5 | c |   |   |   |   |
| 6 | b |   |   |   |   |
| 7 | a |   |   |   |   |

#+BEGIN_SRC python :var table=orig :results output
  # print the header
  print #+name: filtered
  for x in table:
  if x[1] == 'a':
  print |%s % (|.join(map(str, x)))
#+END_SRC

#+RESULTS:
#+begin_example
#+name: filtered
|1|a
|4|a
|7|a
#+end_example
--8---cut here---end---8---

I don't know how to get the column heading row though: apparently babel
strips it from the table it passes to the code block.

Nick



Re: [O] Table filter.

2012-05-08 Thread Marc-Oliver Ihm

Am 08.05.2012 11:45, schrieb x.pi...@gmail.com:

Hi all.
Is table filtering is implementad in org-mode?
Thanks.




Well, I have done something similar, which includes a few more operations than 
filtering.
It uses org-babel and comes as an org-file, which combines code and 
documentation.

Hope, this might be useful for you.

with kind regards, Marc-Oliver Ihm


* Table operations --- filter or combine tables

  This section within the library of babel provides table operations.
  See the documentation just below for details and working examples.

  Author  : Marc-Oliver Ihm i...@ferntreffer.de
  Version : 1.0

** Documentation

*** Introduction

The table operations (currently four) are grouped in two categories:

- Filtering the rows of a single table: keeping or removing
- Combining two tables into one: merging or intersecting
 
All four operations are demonstrated below.

*** Example tables

To demonstrate we need three tables: upper, lower and keys:

#+name: upper
|  1 | A |
|  3 | C |
|  4 | D |
| 10 | J |
|  2 | B |

#+name: lower
| Position | Letter |
|--+|
|2 | b  |
|4 | d  |
|5 | e  |
|6 | h  |

#+name: keys
| Position |
|--|
|1 |
|2 |
|4 |

The tables upper and lower both have two columns and associate a position in
the alphabet with the matching letter.  E.g. the row | 1 | A | from table
upper, just states that the letter A comes at position 1 in the alphabet.

Nearly the same is true for table lower, only that it contains lower case
letters.  Some of its letters (e.g. b) have counterparts in table upper
(B), some (e.g. e) dont.

The table keys finally, contains keys (i.e. positions within the alphabet),
that can be used to select rows from either table upper or lower.

Note, that tables may have column headings or not.

*** Filtering a table

 Keeping rows

 Let's say, we want to select the upper-case letters (i.e. rows from the
 table upper), that are given in table keys (i.e. the first, second and
 fourth letter).

 This can be described as filtering table upper and keeping only those rows,
 that appear in table keys.

 As a babel-call, this reads:

#+call: table-operations-filter-keep(upper,keys)

#+results: table-operations-filter-keep(upper,keys)
| 1 | A |
| 4 | D |
| 2 | B |

 ,which gives exactly those rows from table upper, that are specified in
 keys.

 Removing rows

 Now, if on the contrary you want to filter table upper to remove any rows,
 which are given in table keys:

#+call: table-operations-filter-remove(upper,keys) :colnames yes

#+results: table-operations-filter-remove(upper,keys)
| Position | t2c2 |
|--+--|
|3 | C|
|   10 | J|

 ,which is the expected result.

 Please note, that the call contains the header argument :colnames yes,
 which causes the result table to contain the headings Position and
 t2c2. These headings are taken from the input-tables upper and
 keys. However, as upper does not contain any headings, the heading t2c2
 is generated artificially; it stands for table 2 column 2.

 If you do not want to have column names in the result table, just leave out
 the header argument :colnames yes like in the first example. Note
 however, that :colnames no does not give the expected effect.

*** Combining tables

Now, lets have a look at the tables upper and lower alone and see how to
combine them.

Note, that we only look at combining two tables for simplicity, however, all
operations can be easily scaled up to seven tables.

 Merging rows

 We have two tables, one with upper case letters and one with lower
 case. What now, if you want to have only one table, which contains both,
 upper and lower case letters ?
 
 You may want to merge them:

#+call: table-operations-combine-merge(upper,lower) :colnames yes

#+results: table-operations-combine-merge(upper,lower)
| Position | t1c2 | Letter |
|--+--+|
|1 | A||
|2 | B| b  |
|3 | C||
|4 | D| d  |
|5 |  | e  |
|6 |  | h  |
|   10 | J||


 This result combines both upper and lower case letters and lists them by
 their position within the alphabet.

 Intersecting rows

 If you only want the rows, that are complete (i.e. have both upper and
 lower case letters) you may compute the intersection:

#+call: table-operations-combine-intersect(upper,lower)

#+results: table-operations-combine-intersect(upper,lower)
| 2 | B | b |
| 4 | D | d |


 ,which has only those keys and letters, that appear in both tables.

 Note, that we have ommitted the headeragument :colnames yes so that the
 result table has no headings.

** Internals

   This section is