I have a table as follow:
| Xn | S | Pn |
| 0 | 0 | 0 |
| 1 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 1 | 0 |
I would like to search through columns Xn
and S
and return the value of Pn
for which Xn=1 and S=0
.
Can anyone advise on how I could go about doing this?
#+tblname: example-table
| Xn | S | Pn |
| 0 | 0 | 0 |
| 1 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 1 | 0 |
#+source: compute-table
#+begin_src emacs-lisp :var table=example-table
(require 'cl)
(loop for (xn s pn) in (rest table)
when (and (= xn 1) (= s 0)) collect pn)
#+end_src
#+results: compute-table
| 1 |
Use org-babel: Name the table and use it as input for a function that does the search in a language of your choice (out of the many languages supported by org).
In pseudo code:
#+tblname: my_table
|Xn|S|Pn|
| 0|0|9 |
[...]
#+name filter_table
#+begin_src lang :var tbl=my_table :results output
filter tbl # tbl (my_table by default) is passed in as array of arrays (or list of lists)
print matching Pn
#+end_src
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With