[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Sverweis like function for orgtbl
From: |
John Kitchin |
Subject: |
Re: [O] Sverweis like function for orgtbl |
Date: |
Mon, 16 Feb 2015 13:58:38 -0500 |
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