From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Thorsten Grothe <info@th-grothe.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: Sverweis like function for orgtbl
Date: Mon, 16 Feb 2015 13:58:38 -0500 [thread overview]
Message-ID: <m2h9ulof8h.fsf@andrew.cmu.edu> (raw)
In-Reply-To: <mbt0nh$gns$1@ger.gmane.org>
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
next prev parent reply other threads:[~2015-02-16 18:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-16 15:01 Sverweis like function for orgtbl Thorsten Grothe
2015-02-16 18:58 ` John Kitchin [this message]
2015-02-16 19:42 ` Michael Brand
2015-02-16 21:19 ` Thorsten Grothe
2015-02-17 10:14 ` Karl Voit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2h9ulof8h.fsf@andrew.cmu.edu \
--to=jkitchin@andrew.cmu.edu \
--cc=emacs-orgmode@gnu.org \
--cc=info@th-grothe.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.