emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] extract a column from a table but but an name on the new table


From: Thierry Banel
Subject: Re: [O] extract a column from a table but but an name on the new table
Date: Sat, 26 May 2018 09:20:37 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0

On 24/05/2018 15:08, Uwe Brauer wrote:
Hi

Thierry Banel one of the authors of orgtbl-aggregate.el

Suggested to me the following code, if just want to extract one column
of a table.


#+TBLNAME: raw-data
| 1 | a | 3 |
| 2 | b | 4 |
| 3 | c | 6 |
| 4 | d | 7 |

#+BEGIN_SRC elisp :var data=""
(mapcar (lambda (line)
            (list (nth 2 line)))
         data)
#+END_SRC

#+RESULTS:
| 3 |
| 4 |
| 6 |
| 7 |

It works nicely but how could I obtain the result with a table name,
like:

#+TBLNAME: RESULTS
| 3 |
| 4 |
| 6 |
| 7 |

Or something like this?

Thanks

Uwe Brauer 




You may name the Lisp block like that:

--------------------------------------

#+TBLNAME: raw-data
| 1 | a | 3 |
| 2 | b | 4 |
| 3 | c | 6 |
| 4 | d | 7 |

#+NAME: just-one-column
#+BEGIN_SRC elisp :var data="">
(mapcar (lambda (line)
            (list (nth 2 line)))
         data)
#+END_SRC

#+RESULTS: just-one-column
| 3 |
| 4 |
| 6 |
| 7 |

--------------------------------------


Then you can use the new table in a further processing:

--------------------------------------

#+BEGIN_SRC elisp :var data="">
(mapcar (lambda (line)
          (list (* 1000 (nth 0 line))))
         data)
#+END_SRC

#+RESULTS:
| 3000 |
| 4000 |
| 6000 |
| 7000 |

--------------------------------------






reply via email to

[Prev in Thread] Current Thread [Next in Thread]