From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Sverweis like function for orgtbl Date: Mon, 16 Feb 2015 13:58:38 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41264) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNQsW-00035f-94 for emacs-orgmode@gnu.org; Mon, 16 Feb 2015 13:58:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNQsS-0000Qd-Fz for emacs-orgmode@gnu.org; Mon, 16 Feb 2015 13:58:44 -0500 Received: from smtp.andrew.cmu.edu ([128.2.105.203]:55328) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNQsS-0000QU-C1 for emacs-orgmode@gnu.org; Mon, 16 Feb 2015 13:58:40 -0500 In-reply-to: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Thorsten Grothe Cc: emacs-orgmode@gnu.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