From mboxrd@z Thu Jan 1 00:00:00 1970 From: Subject: Filterring a table for values in a list Date: Sun, 05 Jun 2016 12:11:14 +0200 Message-ID: <87zir07xod.fsf@uranus.home> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9V7r-0004Ol-Ku for emacs-orgmode@gnu.org; Sun, 05 Jun 2016 06:17:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9V7m-0004ZN-Gn for emacs-orgmode@gnu.org; Sun, 05 Jun 2016 06:17:46 -0400 Received: from dd27624.kasserver.com ([85.13.146.80]:45962) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9V7m-0004YM-9g for emacs-orgmode@gnu.org; Sun, 05 Jun 2016 06:17:42 -0400 Received: from uranus.home.evall.org (dslb-188-099-181-222.188.099.pools.vodafone-ip.de [188.99.181.222]) by dd27624.kasserver.com (Postfix) with ESMTPSA id D6A681B80323 for ; Sun, 5 Jun 2016 12:11:14 +0200 (CEST) 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" To: emacs-orgmode@gnu.org 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