Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg96610] Re: Select All Lists Where Any Element is a Given Value
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Tue, 17 Feb 2009 06:25:46 -0500 (EST)

On 2/16/09 at 4:40 PM, gregory.lypny at videotron.ca (Gregory Lypny)
wrote:

>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.

It is unclear to me what you mean by "pull out". If you mean you
want to keep all lists that have na in them somewhere, I would
use Cases rather than Select as follows:

In[1]:= x = {{1, 2, 3}, {8, na, 20}, {-7, 9, na}};
Cases[x, {___, na, ___}]

Out[2]= {{8,na,20},{-7,9,na}}

or if you mean to only keep those items without na in them:

In[3]:= DeleteCases[x, {___, na, ___}]

Out[3]= {{1,2,3}}




  • Prev by Date: Re: Select All Lists Where Any Element is a Given Value
  • Next by Date: RE : [mg96586] Select All Lists Where Any Element
  • 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