* join two or more tables
@ 2019-08-18 8:23 Uwe Brauer
2019-08-18 8:31 ` Uwe Brauer
2019-08-18 10:21 ` Ken Mankoff
0 siblings, 2 replies; 12+ messages in thread
From: Uwe Brauer @ 2019-08-18 8:23 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1027 bytes --]
Hi
I was googling this a bit, I found more complicated scenarios, but not
how to join one or more tables.
For example
#+begin_src
#+tblname: nut
| type | Fiber | Sugar | Protein | Carb |
|----------+-------+-------+---------+------|
| eggplant | 2.5 | 3.2 | 0.8 | 8.6 |
| tomatoe | 0.6 | 2.1 | 0.8 | 3.4 |
| onion | 1.3 | 4.4 | 1.3 | 9.0 |
| egg | 0 | 18.3 | 31.9 | 18.3 |
#+tblname: nut2
| type | Fiber | Sugar | Protein | Carb |
|----------+-------+-------+---------+------|
| rice | 0.2 | 0 | 1.5 | 16.0 |
| bread | 0.7 | 0.7 | 3.3 | 16.0 |
| orange | 3.1 | 11.9 | 1.3 | 17.6 |
| banana | 2.1 | 9.9 | 0.9 | 18.5 |
| tofu | 0.7 | 0.5 | 6.6 | 1.4 |
| nut | 2.6 | 1.3 | 4.9 | 7.2 |
| corn | 4.7 | 1.8 | 2.8 | 21.3 |
#+end_src
I want to generate a new table total-nuts, which is just a combination
of the two tables, nuts and nuts2
Uwe Brauer
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5025 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: join two or more tables
2019-08-18 8:23 join two or more tables Uwe Brauer
@ 2019-08-18 8:31 ` Uwe Brauer
2019-08-18 8:46 ` [SOLVED] (was: join two or more tables) Uwe Brauer
2019-08-18 11:00 ` join two or more tables Jude DaShiell
2019-08-18 10:21 ` Ken Mankoff
1 sibling, 2 replies; 12+ messages in thread
From: Uwe Brauer @ 2019-08-18 8:31 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1676 bytes --]
>>> "UB" == Uwe Brauer <oub@mat.ucm.es> writes:
> Hi
> I was googling this a bit, I found more complicated scenarios, but not
> how to join one or more tables.
> For example
> #+begin_src
> #+tblname: nut
> | type | Fiber | Sugar | Protein | Carb |
> |----------+-------+-------+---------+------|
> | eggplant | 2.5 | 3.2 | 0.8 | 8.6 |
> | tomatoe | 0.6 | 2.1 | 0.8 | 3.4 |
> | onion | 1.3 | 4.4 | 1.3 | 9.0 |
> | egg | 0 | 18.3 | 31.9 | 18.3 |
> #+tblname: nut2
> | type | Fiber | Sugar | Protein | Carb |
> |----------+-------+-------+---------+------|
> | rice | 0.2 | 0 | 1.5 | 16.0 |
> | bread | 0.7 | 0.7 | 3.3 | 16.0 |
> | orange | 3.1 | 11.9 | 1.3 | 17.6 |
> | banana | 2.1 | 9.9 | 0.9 | 18.5 |
> | tofu | 0.7 | 0.5 | 6.6 | 1.4 |
> | nut | 2.6 | 1.3 | 4.9 | 7.2 |
> | corn | 4.7 | 1.8 | 2.8 | 21.3 |
> #+end_src
> I want to generate a new table total-nuts, which is just a combination
> of the two tables, nuts and nuts2
> Uwe Brauer
I found a solution posted in
https://lists.gnu.org/archive/html/emacs-orgmode/2009-09/msg00919.html
However
** Elisp
#+tblname: tab1
| 1 | 2 | 3 |
| 7 | 8 | 9 |
#+tblname: tab2
| 4 | 5 | 6 |
| 10 | 11 | 12 |
Here's a solution in emacs lisp:
#+srcname: column-bind-elisp(a=tab1, b=tab2)
#+begin_src emacs-lisp
(mapcar* 'append a b)
#+end_src
column-bind-elisp
Does not exist any more.
Any ideas?
Uwe Brauer
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5025 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* [SOLVED] (was: join two or more tables)
2019-08-18 8:31 ` Uwe Brauer
@ 2019-08-18 8:46 ` Uwe Brauer
2019-08-18 8:59 ` [rows not columns] (was: [SOLVED]) Uwe Brauer
2019-08-18 11:00 ` join two or more tables Jude DaShiell
1 sibling, 1 reply; 12+ messages in thread
From: Uwe Brauer @ 2019-08-18 8:46 UTC (permalink / raw)
To: emacs-orgmode
>>> "UB" == Uwe Brauer <oub@mat.ucm.es> writes:
>> Hi
>> I was googling this a bit, I found more complicated scenarios, but not
>> how to join one or more tables.
>> For example
>> #+begin_src
>> #+tblname: nut
>> | type | Fiber | Sugar | Protein | Carb |
>> |----------+-------+-------+---------+------|
>> | eggplant | 2.5 | 3.2 | 0.8 | 8.6 |
>> | tomatoe | 0.6 | 2.1 | 0.8 | 3.4 |
>> | onion | 1.3 | 4.4 | 1.3 | 9.0 |
>> | egg | 0 | 18.3 | 31.9 | 18.3 |
>> #+tblname: nut2
>> | type | Fiber | Sugar | Protein | Carb |
>> |----------+-------+-------+---------+------|
>> | rice | 0.2 | 0 | 1.5 | 16.0 |
>> | bread | 0.7 | 0.7 | 3.3 | 16.0 |
>> | orange | 3.1 | 11.9 | 1.3 | 17.6 |
>> | banana | 2.1 | 9.9 | 0.9 | 18.5 |
>> | tofu | 0.7 | 0.5 | 6.6 | 1.4 |
>> | nut | 2.6 | 1.3 | 4.9 | 7.2 |
>> | corn | 4.7 | 1.8 | 2.8 | 21.3 |
>> #+end_src
>> I want to generate a new table total-nuts, which is just a combination
>> of the two tables, nuts and nuts2
>> Uwe Brauer
Best solution found in
https://emacs.stackexchange.com/questions/48508/merge-org-tables
** Solution 1
#+NAME: T1
| col1 | col2 |
| 1 | 2 |
#+NAME: T2
| col3 |
| 3 |
#+BEGIN_SRC emacs-lisp :var t1=T1 t2=T2
(cl-mapcar #'append t1 t2)
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 |
| 1 | 2 | 3 |
** Solution 2
#+NAME: T3
| col1 | col2 |
| 11 | 12 |
| 21 | 22 |
| 31 | 32 |
#+NAME: T4
| col3 |
| 13 |
| 12 |
#+BEGIN_SRC emacs-lisp :var t1=T3 t2=T4 :colnames no
(cl-mapcar #'append t1 t2)
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 |
| 11 | 12 | 13 |
| 21 | 22 | 12 |
** Solution 3
#+NAME: TA
| col1 | col2 |
|------+------|
| 1 | 2 |
#+NAME: TB
| col3 |
|------|
| 3 |
#+BEGIN_SRC emacs-lisp :var t1=TA t2=TB :colnames no
(insert-at 1 (cl-mapcar #'append t1 t2) 'hline)
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 |
|------+------+------|
| 1 | 2 | 3 |
#+begin_src elisp :noexport
(defun insert-at (n list element)
"Insert ELEMENT into LIST at position N.
I.e., (eq ELEMENT (nth N (insert-at N LIST ELEMENT)))."
(if (eq n 0)
(cons element list)
(let ((link (nthcdr (1- n) list)))
(setcdr link (cons element (cdr link))))
list))
#+end_src
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: join two or more tables
2019-08-18 8:31 ` Uwe Brauer
2019-08-18 8:46 ` [SOLVED] (was: join two or more tables) Uwe Brauer
@ 2019-08-18 11:00 ` Jude DaShiell
1 sibling, 0 replies; 12+ messages in thread
From: Jude DaShiell @ 2019-08-18 11:00 UTC (permalink / raw)
To: Uwe Brauer, emacs-orgmode
In that situation I made 3 files header; t1, and t2. The header file
had the two lines at the top of both tables. The t1 and t2 files had
only record lines in them without the footer. Then cat header t1 t2
>newtable. Once done open newtable and be sure it works in emacs and
append that footer line to it and perhaps put it into a #Begin-src
#End-src block.
On Sun, 18 Aug 2019, Uwe Brauer wrote:
> Date: Sun, 18 Aug 2019 04:31:04
> From: Uwe Brauer <oub@mat.ucm.es>
> To: emacs-orgmode@gnu.org
> Subject: Re: [O] join two or more tables
>
> >>> "UB" == Uwe Brauer <oub@mat.ucm.es> writes:
>
> > Hi
>
> > I was googling this a bit, I found more complicated scenarios, but not
> > how to join one or more tables.
>
> > For example
>
> > #+begin_src
>
> > #+tblname: nut
> > | type | Fiber | Sugar | Protein | Carb |
> > |----------+-------+-------+---------+------|
> > | eggplant | 2.5 | 3.2 | 0.8 | 8.6 |
> > | tomatoe | 0.6 | 2.1 | 0.8 | 3.4 |
> > | onion | 1.3 | 4.4 | 1.3 | 9.0 |
> > | egg | 0 | 18.3 | 31.9 | 18.3 |
>
>
> > #+tblname: nut2
> > | type | Fiber | Sugar | Protein | Carb |
> > |----------+-------+-------+---------+------|
> > | rice | 0.2 | 0 | 1.5 | 16.0 |
> > | bread | 0.7 | 0.7 | 3.3 | 16.0 |
> > | orange | 3.1 | 11.9 | 1.3 | 17.6 |
> > | banana | 2.1 | 9.9 | 0.9 | 18.5 |
> > | tofu | 0.7 | 0.5 | 6.6 | 1.4 |
> > | nut | 2.6 | 1.3 | 4.9 | 7.2 |
> > | corn | 4.7 | 1.8 | 2.8 | 21.3 |
> > #+end_src
>
>
> > I want to generate a new table total-nuts, which is just a combination
> > of the two tables, nuts and nuts2
>
>
> > Uwe Brauer
>
> I found a solution posted in
>
> https://lists.gnu.org/archive/html/emacs-orgmode/2009-09/msg00919.html
>
> However
>
> ** Elisp
> #+tblname: tab1
> | 1 | 2 | 3 |
> | 7 | 8 | 9 |
>
> #+tblname: tab2
> | 4 | 5 | 6 |
> | 10 | 11 | 12 |
>
> Here's a solution in emacs lisp:
>
> #+srcname: column-bind-elisp(a=tab1, b=tab2)
> #+begin_src emacs-lisp
> (mapcar* 'append a b)
> #+end_src
>
>
> column-bind-elisp
>
> Does not exist any more.
>
> Any ideas?
>
> Uwe Brauer
>
--
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: join two or more tables
2019-08-18 8:23 join two or more tables Uwe Brauer
2019-08-18 8:31 ` Uwe Brauer
@ 2019-08-18 10:21 ` Ken Mankoff
2019-08-18 10:24 ` Uwe Brauer
1 sibling, 1 reply; 12+ messages in thread
From: Ken Mankoff @ 2019-08-18 10:21 UTC (permalink / raw)
To: Uwe Brauer; +Cc: emacs-orgmode
On 2019-08-18 at 04:23 -04, Uwe Brauer <oub@mat.ucm.es> wrote...
> I was googling this a bit, I found more complicated scenarios, but not
> how to join one or more tables.
>
> [...]
>
> I want to generate a new table total-nuts, which is just a combination
> of the two tables, nuts and nuts2
Does https://github.com/tbanel/orgtbljoin do what you want?
-k.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: join two or more tables
2019-08-18 10:21 ` Ken Mankoff
@ 2019-08-18 10:24 ` Uwe Brauer
2019-08-18 10:49 ` Achim Gratz
0 siblings, 1 reply; 12+ messages in thread
From: Uwe Brauer @ 2019-08-18 10:24 UTC (permalink / raw)
To: Ken Mankoff; +Cc: Uwe Brauer, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 926 bytes --]
>>> "KM" == Ken Mankoff <mankoff@gmail.com> writes:
> On 2019-08-18 at 04:23 -04, Uwe Brauer <oub@mat.ucm.es> wrote...
>> I was googling this a bit, I found more complicated scenarios, but not
>> how to join one or more tables.
>>
>> [...]
>>
>> I want to generate a new table total-nuts, which is just a combination
>> of the two tables, nuts and nuts2
> Does https://github.com/tbanel/orgtbljoin do what you want?
Thanks I knew about it, but it seems very sophisticated and column, not
row based.
Meanwhile I found the following, R-based, solution
* Using R to combine columns, important the first row must coincide!
#+tblname: TC
| a | b | c |
|---+---+---|
| 1 | 2 | 3 |
| 7 | 8 | 9 |
#+tblname: TD
| a | b | c |
|----+----+----|
| 4 | 5 | 6 |
| 10 | 11 | 12 |
#+begin_src R :colnames t :var t1=TC t2=TD
rbind(t1, t2)
#+end_src
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5025 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: join two or more tables
2019-08-18 10:24 ` Uwe Brauer
@ 2019-08-18 10:49 ` Achim Gratz
2019-08-18 11:34 ` Uwe Brauer
0 siblings, 1 reply; 12+ messages in thread
From: Achim Gratz @ 2019-08-18 10:49 UTC (permalink / raw)
To: emacs-orgmode
Uwe Brauer writes:
> Thanks I knew about it, but it seems very sophisticated and column, not
> row based.
Well, if simple-minded suits you (i.e. the columns are known to have the
same order):
Tables in Org are lists with rows as their elements, and a row is either
a symbol or a list of column elements. So just concatenating the two
lists does (almost) the right thing. If you know the row has headers,
you need to skip until the first real data row in the second table
(i.e. skip the first row, the first header and then resume the concat).
Your other option is just grabbing the text of both tables, emit it as a
single entity (again you may want to remove the header on the second
table) and then call org-align-table on it.
Regards,
Achim.
--
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+
SD adaptations for KORG EX-800 and Poly-800MkII V0.9:
http://Synth.Stromeko.net/Downloads.html#KorgSDada
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: join two or more tables
2019-08-18 10:49 ` Achim Gratz
@ 2019-08-18 11:34 ` Uwe Brauer
2019-08-23 18:09 ` Achim Gratz
0 siblings, 1 reply; 12+ messages in thread
From: Uwe Brauer @ 2019-08-18 11:34 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1356 bytes --]
>>> "AG" == Achim Gratz <Stromeko@nexgo.de> writes:
> Uwe Brauer writes:
>> Thanks I knew about it, but it seems very sophisticated and column, not
>> row based.
> Well, if simple-minded suits you (i.e. the columns are known to have the
> same order):
> Tables in Org are lists with rows as their elements, and a row is either
> a symbol or a list of column elements. So just concatenating the two
> lists does (almost) the right thing. If you know the row has headers,
> you need to skip until the first real data row in the second table
> (i.e. skip the first row, the first header and then resume the concat).
> Your other option is just grabbing the text of both tables, emit it as a
> single entity (again you may want to remove the header on the second
> table) and then call org-align-table on it.
Hm, thanks but could you post an example (the one I finally used is
based on R and goes as follows
#+tblname: TC
| a | b | c |
|---+---+---|
| 1 | 2 | 3 |
| 7 | 8 | 9 |
#+tblname: TD
| a | b | c |
|----+----+----|
| 4 | 5 | 6 |
| 10 | 11 | 12 |
#+begin_src R :colnames t :var t1=TC t2=TD
rbind(t1, t2)
#+end_src
#+RESULTS:
| a | b | c |
|----+----+----|
| 1 | 2 | 3 |
| 7 | 8 | 9 |
| 4 | 5 | 6 |
| 10 | 11 | 12 |
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5025 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* join two or more tables
@ 2019-08-23 9:55 emanuel.charpentier
2019-08-23 10:54 ` Uwe Brauer
0 siblings, 1 reply; 12+ messages in thread
From: emanuel.charpentier @ 2019-08-23 9:55 UTC (permalink / raw)
To: oub; +Cc: emacs-orgmode
> Hi
>
> I was googling this a bit, I found more complicated scenarios, but
> not how to join one or more tables.
>
> For example
> #+begin_src
>
> #+tblname: nut
> | type | Fiber | Sugar | Protein | Carb |
> |----------+-------+-------+---------+------|
> | eggplant | 2.5 | 3.2 | 0.8 | 8.6 |
> | tomatoe | 0.6 | 2.1 | 0.8 | 3.4 |
> | onion | 1.3 | 4.4 | 1.3 | 9.0 |
> | egg | 0 | 18.3 | 31.9 | 18.3 |
>
>
> #+tblname: nut2
> | type | Fiber | Sugar | Protein | Carb |
> |----------+-------+-------+---------+------|
> | rice | 0.2 | 0 | 1.5 | 16.0 |
> | bread | 0.7 | 0.7 | 3.3 | 16.0 |
> | orange | 3.1 | 11.9 | 1.3 | 17.6 |
> | banana | 2.1 | 9.9 | 0.9 | 18.5 |
> | tofu | 0.7 | 0.5 | 6.6 | 1.4 |
> | nut | 2.6 | 1.3 | 4.9 | 7.2 |
> | corn | 4.7 | 1.8 | 2.8 | 21.3 |
> #+end_src
What about:
#+begin_src emacs-lisp :var t1=nut :var t2=nut2 :colnames yes
(append t1 t2)
#+end_src
#+RESULTS:
| type | Fiber | Sugar | Protein | Carb |
|----------+-------+-------+---------+------|
| eggplant | 2.5 | 3.2 | 0.8 | 8.6 |
| tomatoe | 0.6 | 2.1 | 0.8 | 3.4 |
| onion | 1.3 | 4.4 | 1.3 | 9.0 |
| egg | 0 | 18.3 | 31.9 | 18.3 |
| rice | 0.2 | 0 | 1.5 | 16.0 |
| bread | 0.7 | 0.7 | 3.3 | 16.0 |
| orange | 3.1 | 11.9 | 1.3 | 17.6 |
| banana | 2.1 | 9.9 | 0.9 | 18.5 |
| tofu | 0.7 | 0.5 | 6.6 | 1.4 |
| nut | 2.6 | 1.3 | 4.9 | 7.2 |
| corn | 4.7 | 1.8 | 2.8 | 21.3 |
Of course, this works because both tables have headers, which can be
handled by the ":colnames yes" header-argument. If both are headerless,
"colnames: no" would do the trick.
Handling the case where one has headers and the other not, or when
there are hlines in the table is still a conudrum for me: I haven't
(yet) been able to find the documentation on how these things are
stored...
HTH,
--
Emmanuel Charpentier
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2019-08-23 18:10 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-18 8:23 join two or more tables Uwe Brauer
2019-08-18 8:31 ` Uwe Brauer
2019-08-18 8:46 ` [SOLVED] (was: join two or more tables) Uwe Brauer
2019-08-18 8:59 ` [rows not columns] (was: [SOLVED]) Uwe Brauer
2019-08-18 11:00 ` join two or more tables Jude DaShiell
2019-08-18 10:21 ` Ken Mankoff
2019-08-18 10:24 ` Uwe Brauer
2019-08-18 10:49 ` Achim Gratz
2019-08-18 11:34 ` Uwe Brauer
2019-08-23 18:09 ` Achim Gratz
-- strict thread matches above, loose matches on Subject: below --
2019-08-23 9:55 emanuel.charpentier
2019-08-23 10:54 ` Uwe Brauer
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).