Hi, based on a post on http://emacs.stackexchange.com/questions/20129/how-can-i-filter-table-in-org-mode about filtering a table row-wise, I want to write a filter to select rows which matches some values in a list:
#+NAME: table1 | col1 | col2 | col3 | col4 | col5 | |-------+------+------+------+------| | row0 | 0 | CH | CH | 0 | | row1 | 2 | D | CN | 5 | | row2 | 4 | USA | PL | 10 | | row3 | 6 | CN | D | 15 | | row4 | 8 | JP | USA | 20 | | row5 | 10 | PL | PL | 25 | | row6 | 12 | USA | JP | 30 | | row7 | 14 | D | CN | 35 | | row8 | 16 | PL | USA | 40 | | row9 | 18 | CN | D | 45 | | row10 | 20 | CH | CH | 50 | I like to filter col4 for "USA" and "CN" #+NAME: my-filter #+BEGIN_SRC elisp :var tbl=table1 val='("" "USA" "CN") :colnames y (cl-loop for row in tbl if (member (nth 3 row) val) collect row into newtbl finally return newtbl) #+END_SRC with result #+RESULTS: my-filter | row1 | 2 | D | CN | 5 | | row4 | 8 | JP | USA | 20 | | row7 | 14 | D | CN | 35 | | row8 | 16 | PL | USA | 40 | My questions: 1) How can I preserve the column names in the result? The code on http://emacs.stackexchange.com/questions/20129/how-can-i-filter-table-in-org-mode preserves the table header. 2) Without the "" in the list, only rows matching the last element "CN" are selected. So I think the code is wrong. Are there any ideas to improve the code? Thanks, Sven