MathGroup Archive 2009

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

Search the Archive

Re: Select All Lists Where Any Element is a Given Value

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96626] Re: Select All Lists Where Any Element is a Given Value
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Tue, 17 Feb 2009 06:28:44 -0500 (EST)
  • References: <gncmgo$fkq$1@smc.vnet.net>

Gregory Lypny wrote:
> Hello everyone,
> 
> Suppose I have the list
> 
> 	X = {{1, 2, 3}, {8, NA, 20}, {-7, 9, NA}},
> 
> where NA is a string, although it need not be.  How can I use Select  
> to pull out all lists in X where NA appears in any element?  In this  
> example, I want to pull out the second and third list.
> 
> 		Regards,
> 
> 			Gregory

Not really sure what you want, but this gives you all lists that don't
contain NA:
 		
Select[X, FreeQ[#, NA] &]

while this gives you all lists that do contain NA:

Select[X, ! FreeQ[#, NA] &]

the above look for the symbol NA, if you want the string "NA", that will
work just as well:

Select[X, ! FreeQ[#, "NA"] &]

and if you don't care whether its a string or a symbol:

Select[X, ! FreeQ[#, "NA" | NA] &]

you should also consider to select depending on whether something does
contain numeric data only, which is in many cases what one really wants
and can be done with something like:

Select[X, VectorQ[#, NumericQ] &]

or

Select[X, ! VectorQ[#, NumericQ] &]

hth,

albert



  • Prev by Date: Re: Problem with the 'if' command
  • Next by Date: Help with project needed
  • Previous by thread: Re: Select All Lists Where Any Element is a Given Value
  • Next by thread: Re: Select All Lists Where Any Element is a Given Value