Re: [O] Sverweis like function for orgtbl

2015-02-17 Thread Karl Voit
* Thorsten Grothe i...@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




Re: [O] Sverweis like function for orgtbl

2015-02-16 Thread John Kitchin
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



Re: [O] Sverweis like function for orgtbl

2015-02-16 Thread Michael Brand
Hi Thorsten

On Mon, Feb 16, 2015 at 4:01 PM, Thorsten Grothe i...@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



Re: [O] Sverweis like function for orgtbl

2015-02-16 Thread Thorsten Grothe
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




[O] Sverweis like function for orgtbl

2015-02-16 Thread Thorsten Grothe
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