Re: Select All Lists Where Any Element is a Given Value
- To: mathgroup at smc.vnet.net
- Subject: [mg96605] Re: [mg96586] Select All Lists Where Any Element is a Given Value
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Tue, 17 Feb 2009 06:24:52 -0500 (EST)
- Reply-to: hanlonr at cox.net
X = {{1, 2, 3}, {8, NA, 20}, {-7, 9, NA}};
Select[X, ! FreeQ[#, NA] &]
{{8, NA, 20}, {-7, 9, NA}}
Cases[X, _?(! FreeQ[#, NA] &)]
{{8, NA, 20}, {-7, 9, NA}}
DeleteCases[X, _?(FreeQ[#, NA] &)]
{{8, NA, 20}, {-7, 9, NA}}
X /. _List?(FreeQ[#, NA] &) :> Sequence[]
{{8, NA, 20}, {-7, 9, NA}}
Bob Hanlon
---- Gregory Lypny <gregory.lypny at videotron.ca> 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