MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Selecting table rows

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66051] Re: [mg66037] Selecting table rows
  • From: Arturas Acus <acus at itpa.lt>
  • Date: Fri, 28 Apr 2006 06:32:24 -0400 (EDT)
  • References: <200604270626.CAA29283@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Kt, 2006-04-27 at 02:26 -0400, Skirmantas wrote:
> I have a 2D-table whose first column contains the unique identifiers (ID) of each row (IDs can be any numbers). I need to delete all rows whose IDs are not members of another, control list.
> 
> The following works, but I'm wondering if there is a shorter way to do this.
> 
> TBL = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}, {17, 18, 19, 20}};
> 
> CNTR = {1, 9, 17};
> 
> Map[Part[TBL, #]&, Flatten[Map[Position[Transpose[TBL][[1]], #]&, CNTR]]]
>   
> Thanks --
> 
> Skirmantas


The following short code based on Select pick up requested control
lists 

Select[TBL, MemberQ[CNTR, #[[1]]] &]


-- 
Arturas Acus <acus at itpa.lt>


  • Prev by Date: saving lists/plots in another notebook
  • Next by Date: A Conditional File Import
  • Previous by thread: Selecting table rows
  • Next by thread: Re: Selecting table rows