* Sverweis like function for orgtbl
@ 2015-02-16 15:01 Thorsten Grothe
2015-02-16 18:58 ` John Kitchin
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Thorsten Grothe @ 2015-02-16 15:01 UTC (permalink / raw)
To: emacs-orgmode
Dear Org-users,
I got this table:
| Menge (x) | P(x) | E(x) | K(x) | Gewinn |
|-----------+------+--------+--------+---------|
| 0 | 20 | 0.00 | 140.00 | -140.00 |
| 10 | 18 | 180.00 | 180.00 | 0.00 |
| 20 | 16 | 320.00 | 220.00 | 100.00 |
| 30 | 14 | 420.00 | 260.00 | 160.00 |
and would like to find the highest value in the column "Gewinn" = 160 go
two cells left to E(x), read out the value (420) and put this in a remote
orgtbl. This is something similar to Sverweis in Excel.
I found no predefined function for orgtbl, is it possible?
Thanks in advance!
Regards
Thorsten
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Sverweis like function for orgtbl
2015-02-16 15:01 Sverweis like function for orgtbl Thorsten Grothe
@ 2015-02-16 18:58 ` John Kitchin
2015-02-16 19:42 ` Michael Brand
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: John Kitchin @ 2015-02-16 18:58 UTC (permalink / raw)
To: Thorsten Grothe; +Cc: emacs-orgmode
Here is one way to do it in a code block.
#+tblname: tab-data
| Menge (x) | P(x) | E(x) | K(x) | Gewinn |
|-----------+------+--------+--------+---------|
| 0 | 20 | 0.00 | 140.00 | -140.00 |
| 10 | 18 | 180.00 | 180.00 | 0.00 |
| 20 | 16 | 320.00 | 220.00 | 100.00 |
| 30 | 14 | 420.00 | 260.00 | 160.00 |
#+BEGIN_SRC emacs-lisp :var data=tab-data :results code
(let ((c4 (mapcar (lambda (x) (nth 4 x)) data))
(c2 (mapcar (lambda (x) (nth 2 x)) data)))
(nth (-elem-index (-max c4) c4) c2))
#+END_SRC
#+RESULTS:
#+BEGIN_SRC emacs-lisp
420.0
#+END_SRC
If you put the cursor on -140, and run this code, it does sort of the
same thing.
#+BEGIN_SRC emacs-lisp
(defun jt ()
"find max in column, message the corresponding value in column 3."
(interactive)
(let ((max (string-to-number (org-table-get-field)))
(row (org-table-current-line)))
(while (org-table-next-row)
(when (> (string-to-number (org-table-get-field)) max)
(setq max (string-to-number (org-table-get-field))
ind (org-table-current-line))))
(org-table-goto-line ind)
; columns start at 1?
(org-table-goto-column 3)
(message-box "%s" (org-table-get-field))))
#+END_SRC
Thorsten Grothe writes:
> Dear Org-users,
>
> I got this table:
>
> | Menge (x) | P(x) | E(x) | K(x) | Gewinn |
> |-----------+------+--------+--------+---------|
> | 0 | 20 | 0.00 | 140.00 | -140.00 |
> | 10 | 18 | 180.00 | 180.00 | 0.00 |
> | 20 | 16 | 320.00 | 220.00 | 100.00 |
> | 30 | 14 | 420.00 | 260.00 | 160.00 |
>
> and would like to find the highest value in the column "Gewinn" = 160 go
> two cells left to E(x), read out the value (420) and put this in a remote
> orgtbl. This is something similar to Sverweis in Excel.
>
> I found no predefined function for orgtbl, is it possible?
>
> Thanks in advance!
>
> Regards
> Thorsten
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Sverweis like function for orgtbl
2015-02-16 15:01 Sverweis like function for orgtbl Thorsten Grothe
2015-02-16 18:58 ` John Kitchin
@ 2015-02-16 19:42 ` Michael Brand
2015-02-16 21:19 ` Thorsten Grothe
2015-02-17 10:14 ` Karl Voit
3 siblings, 0 replies; 5+ messages in thread
From: Michael Brand @ 2015-02-16 19:42 UTC (permalink / raw)
To: Thorsten Grothe; +Cc: Org Mode
Hi Thorsten
On Mon, Feb 16, 2015 at 4:01 PM, Thorsten Grothe <info@th-grothe.de> wrote:
> I got this table:
>
> | Menge (x) | P(x) | E(x) | K(x) | Gewinn |
> |-----------+------+--------+--------+---------|
> | 0 | 20 | 0.00 | 140.00 | -140.00 |
> | 10 | 18 | 180.00 | 180.00 | 0.00 |
> | 20 | 16 | 320.00 | 220.00 | 100.00 |
> | 30 | 14 | 420.00 | 260.00 | 160.00 |
>
> and would like to find the highest value in the column "Gewinn" = 160 go
> two cells left to E(x), read out the value (420) and put this in a remote
> orgtbl. This is something similar to Sverweis in Excel.
For a solution with a table formula see
(info "(org) Lookup functions")
or
http://orgmode.org/manual/Lookup-functions.html
It contains also a link to a tutorial.
Michael
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Sverweis like function for orgtbl
2015-02-16 15:01 Sverweis like function for orgtbl Thorsten Grothe
2015-02-16 18:58 ` John Kitchin
2015-02-16 19:42 ` Michael Brand
@ 2015-02-16 21:19 ` Thorsten Grothe
2015-02-17 10:14 ` Karl Voit
3 siblings, 0 replies; 5+ messages in thread
From: Thorsten Grothe @ 2015-02-16 21:19 UTC (permalink / raw)
To: emacs-orgmode
Thank you John and Michael for your suggestions, I will see if my
knowledge is wide enough to understand this, unfortunately I'm a emacs
newbie :-)
Anyway I will answer after testing your suggestions!
Regards
Thorsten
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Sverweis like function for orgtbl
2015-02-16 15:01 Sverweis like function for orgtbl Thorsten Grothe
` (2 preceding siblings ...)
2015-02-16 21:19 ` Thorsten Grothe
@ 2015-02-17 10:14 ` Karl Voit
3 siblings, 0 replies; 5+ messages in thread
From: Karl Voit @ 2015-02-17 10:14 UTC (permalink / raw)
To: emacs-orgmode
* Thorsten Grothe <info@th-grothe.de> wrote:
> Dear Org-users,
>
> I got this table:
>
>| Menge (x) | P(x) | E(x) | K(x) | Gewinn |
>|-----------+------+--------+--------+---------|
>| 0 | 20 | 0.00 | 140.00 | -140.00 |
>| 10 | 18 | 180.00 | 180.00 | 0.00 |
>| 20 | 16 | 320.00 | 220.00 | 100.00 |
>| 30 | 14 | 420.00 | 260.00 | 160.00 |
>
> and would like to find the highest value in the column "Gewinn" = 160 go
> two cells left to E(x), read out the value (420) and put this in a remote
> orgtbl. This is something similar to Sverweis in Excel.
You might be interested in:
http://sachachua.com/blog/2015/01/getting-data-org-mode-tables/
or
https://github.com/tbanel/orgaggregate
I'd give it a try with orgaggregate since it provides a lot of
reference methods. Did not try it by myself - it's on my todo list
for the weekend (again) :-)
--
mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
> get Memacs from https://github.com/novoid/Memacs <
https://github.com/novoid/extract_pdf_annotations_to_orgmode + more on github
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-02-17 10:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-16 15:01 Sverweis like function for orgtbl Thorsten Grothe
2015-02-16 18:58 ` John Kitchin
2015-02-16 19:42 ` Michael Brand
2015-02-16 21:19 ` Thorsten Grothe
2015-02-17 10:14 ` Karl Voit
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.