Merge org tablesTOC of tables for org-mode long tablesCreate table for existing data using org-modeCan org tables cooperate with my customized dates?Is there a python tool for parsing org-mode tables?Auto-update org tables before each exportHow to export org tables with cells on multiple lines?Controling what an org-link points to with variablesConditional evaluation of org mode tables?Number-separators in org-mode tablesOrg-Mode How to position tables correctly when exporting to Latex?
Using parameter substitution on a Bash array
Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?
How to be diplomatic in refusing to write code that breaches the privacy of our users
Is it correct to write "is not focus on"?
Was the picture area of a CRT a parallelogram (instead of a true rectangle)?
Ways to speed up user implemented RK4
Teaching indefinite integrals that require special-casing
How do I define a right arrow with bar in LaTeX?
Why does John Bercow say “unlock” after reading out the results of a vote?
Student evaluations of teaching assistants
What's the purpose of "true" in bash "if sudo true; then"
Everything Bob says is false. How does he get people to trust him?
Time travel short story where a man arrives in the late 19th century in a time machine and then sends the machine back into the past
Are there any comparative studies done between Ashtavakra Gita and Buddhim?
Generic lambda vs generic function give different behaviour
Coordinate position not precise
Is there an Impartial Brexit Deal comparison site?
What is the oldest known work of fiction?
How will losing mobility of one hand affect my career as a programmer?
Lay out the Carpet
Displaying the order of the columns of a table
What would happen if the UK refused to take part in EU Parliamentary elections?
What is the term when two people sing in harmony, but they aren't singing the same notes?
Why Were Madagascar and New Zealand Discovered So Late?
Merge org tables
TOC of tables for org-mode long tablesCreate table for existing data using org-modeCan org tables cooperate with my customized dates?Is there a python tool for parsing org-mode tables?Auto-update org tables before each exportHow to export org tables with cells on multiple lines?Controling what an org-link points to with variablesConditional evaluation of org mode tables?Number-separators in org-mode tablesOrg-Mode How to position tables correctly when exporting to Latex?
Let's say I have the following org-tables:
| col1 | col2 |
| 1 | 2 |
| col3 |
| 3 |
What's the easiest programmatic way to get the following output:
| col1 | col2 | col3 |
| 1 | 2 | 3 |
org-mode
add a comment |
Let's say I have the following org-tables:
| col1 | col2 |
| 1 | 2 |
| col3 |
| 3 |
What's the easiest programmatic way to get the following output:
| col1 | col2 | col3 |
| 1 | 2 | 3 |
org-mode
Manually or programmatically?
– choroba
Mar 21 at 15:36
Programmatically.
– андрэ
Mar 21 at 15:47
add a comment |
Let's say I have the following org-tables:
| col1 | col2 |
| 1 | 2 |
| col3 |
| 3 |
What's the easiest programmatic way to get the following output:
| col1 | col2 | col3 |
| 1 | 2 | 3 |
org-mode
Let's say I have the following org-tables:
| col1 | col2 |
| 1 | 2 |
| col3 |
| 3 |
What's the easiest programmatic way to get the following output:
| col1 | col2 | col3 |
| 1 | 2 | 3 |
org-mode
org-mode
edited Mar 21 at 16:25
андрэ
asked Mar 21 at 15:32
андрэандрэ
1275
1275
Manually or programmatically?
– choroba
Mar 21 at 15:36
Programmatically.
– андрэ
Mar 21 at 15:47
add a comment |
Manually or programmatically?
– choroba
Mar 21 at 15:36
Programmatically.
– андрэ
Mar 21 at 15:47
Manually or programmatically?
– choroba
Mar 21 at 15:36
Manually or programmatically?
– choroba
Mar 21 at 15:36
Programmatically.
– андрэ
Mar 21 at 15:47
Programmatically.
– андрэ
Mar 21 at 15:47
add a comment |
1 Answer
1
active
oldest
votes
You can use cl-mapcar
.
#+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 |
A nice side-effect of that solution is that it does not hurt if one table stops early. The resulting table is just as long as the shortest input table.
#+NAME: T1
| col1 | col2 |
| 11 | 12 |
| 21 | 22 |
| 31 | 32 |
#+NAME: T2
| col3 |
| 13 |
| 12 |
#+BEGIN_SRC emacs-lisp :var t1=T1 t2=T2 :colnames no
(cl-mapcar #'append t1 t2)
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 |
| 11 | 12 | 13 |
| 21 | 22 | 12 |
If you have actually headers you can use:
#+NAME: T1
| col1 | col2 |
|------+------|
| 1 | 2 |
#+NAME: T2
| col3 |
|------|
| 3 |
#+BEGIN_SRC emacs-lisp :var t1=T1 t2=T2 :colnames no
(insert-at 1 (cl-mapcar #'append t1 t2) 'hline)
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 |
|------+------+------|
| 1 | 2 | 3 |
Thereby, insert-at
is defined by:
(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))
That's... lovely!
– андрэ
Mar 21 at 16:39
1
Uups the definition ofinsert-at
is from my own lisp library. I'll replace it with something standard in a moment...
– Tobias
Mar 21 at 16:53
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "583"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2femacs.stackexchange.com%2fquestions%2f48508%2fmerge-org-tables%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use cl-mapcar
.
#+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 |
A nice side-effect of that solution is that it does not hurt if one table stops early. The resulting table is just as long as the shortest input table.
#+NAME: T1
| col1 | col2 |
| 11 | 12 |
| 21 | 22 |
| 31 | 32 |
#+NAME: T2
| col3 |
| 13 |
| 12 |
#+BEGIN_SRC emacs-lisp :var t1=T1 t2=T2 :colnames no
(cl-mapcar #'append t1 t2)
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 |
| 11 | 12 | 13 |
| 21 | 22 | 12 |
If you have actually headers you can use:
#+NAME: T1
| col1 | col2 |
|------+------|
| 1 | 2 |
#+NAME: T2
| col3 |
|------|
| 3 |
#+BEGIN_SRC emacs-lisp :var t1=T1 t2=T2 :colnames no
(insert-at 1 (cl-mapcar #'append t1 t2) 'hline)
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 |
|------+------+------|
| 1 | 2 | 3 |
Thereby, insert-at
is defined by:
(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))
That's... lovely!
– андрэ
Mar 21 at 16:39
1
Uups the definition ofinsert-at
is from my own lisp library. I'll replace it with something standard in a moment...
– Tobias
Mar 21 at 16:53
add a comment |
You can use cl-mapcar
.
#+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 |
A nice side-effect of that solution is that it does not hurt if one table stops early. The resulting table is just as long as the shortest input table.
#+NAME: T1
| col1 | col2 |
| 11 | 12 |
| 21 | 22 |
| 31 | 32 |
#+NAME: T2
| col3 |
| 13 |
| 12 |
#+BEGIN_SRC emacs-lisp :var t1=T1 t2=T2 :colnames no
(cl-mapcar #'append t1 t2)
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 |
| 11 | 12 | 13 |
| 21 | 22 | 12 |
If you have actually headers you can use:
#+NAME: T1
| col1 | col2 |
|------+------|
| 1 | 2 |
#+NAME: T2
| col3 |
|------|
| 3 |
#+BEGIN_SRC emacs-lisp :var t1=T1 t2=T2 :colnames no
(insert-at 1 (cl-mapcar #'append t1 t2) 'hline)
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 |
|------+------+------|
| 1 | 2 | 3 |
Thereby, insert-at
is defined by:
(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))
That's... lovely!
– андрэ
Mar 21 at 16:39
1
Uups the definition ofinsert-at
is from my own lisp library. I'll replace it with something standard in a moment...
– Tobias
Mar 21 at 16:53
add a comment |
You can use cl-mapcar
.
#+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 |
A nice side-effect of that solution is that it does not hurt if one table stops early. The resulting table is just as long as the shortest input table.
#+NAME: T1
| col1 | col2 |
| 11 | 12 |
| 21 | 22 |
| 31 | 32 |
#+NAME: T2
| col3 |
| 13 |
| 12 |
#+BEGIN_SRC emacs-lisp :var t1=T1 t2=T2 :colnames no
(cl-mapcar #'append t1 t2)
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 |
| 11 | 12 | 13 |
| 21 | 22 | 12 |
If you have actually headers you can use:
#+NAME: T1
| col1 | col2 |
|------+------|
| 1 | 2 |
#+NAME: T2
| col3 |
|------|
| 3 |
#+BEGIN_SRC emacs-lisp :var t1=T1 t2=T2 :colnames no
(insert-at 1 (cl-mapcar #'append t1 t2) 'hline)
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 |
|------+------+------|
| 1 | 2 | 3 |
Thereby, insert-at
is defined by:
(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))
You can use cl-mapcar
.
#+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 |
A nice side-effect of that solution is that it does not hurt if one table stops early. The resulting table is just as long as the shortest input table.
#+NAME: T1
| col1 | col2 |
| 11 | 12 |
| 21 | 22 |
| 31 | 32 |
#+NAME: T2
| col3 |
| 13 |
| 12 |
#+BEGIN_SRC emacs-lisp :var t1=T1 t2=T2 :colnames no
(cl-mapcar #'append t1 t2)
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 |
| 11 | 12 | 13 |
| 21 | 22 | 12 |
If you have actually headers you can use:
#+NAME: T1
| col1 | col2 |
|------+------|
| 1 | 2 |
#+NAME: T2
| col3 |
|------|
| 3 |
#+BEGIN_SRC emacs-lisp :var t1=T1 t2=T2 :colnames no
(insert-at 1 (cl-mapcar #'append t1 t2) 'hline)
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 |
|------+------+------|
| 1 | 2 | 3 |
Thereby, insert-at
is defined by:
(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))
edited Mar 21 at 18:35
answered Mar 21 at 16:37
TobiasTobias
14.4k1933
14.4k1933
That's... lovely!
– андрэ
Mar 21 at 16:39
1
Uups the definition ofinsert-at
is from my own lisp library. I'll replace it with something standard in a moment...
– Tobias
Mar 21 at 16:53
add a comment |
That's... lovely!
– андрэ
Mar 21 at 16:39
1
Uups the definition ofinsert-at
is from my own lisp library. I'll replace it with something standard in a moment...
– Tobias
Mar 21 at 16:53
That's... lovely!
– андрэ
Mar 21 at 16:39
That's... lovely!
– андрэ
Mar 21 at 16:39
1
1
Uups the definition of
insert-at
is from my own lisp library. I'll replace it with something standard in a moment...– Tobias
Mar 21 at 16:53
Uups the definition of
insert-at
is from my own lisp library. I'll replace it with something standard in a moment...– Tobias
Mar 21 at 16:53
add a comment |
Thanks for contributing an answer to Emacs Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2femacs.stackexchange.com%2fquestions%2f48508%2fmerge-org-tables%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Manually or programmatically?
– choroba
Mar 21 at 15:36
Programmatically.
– андрэ
Mar 21 at 15:47