Re: Selecting Rows Where All Columns Satisfy a Condition
- To: mathgroup at smc.vnet.net
- Subject: [mg82609] Re: Selecting Rows Where All Columns Satisfy a Condition
- From: Albert <awnl at arcor.net>
- Date: Fri, 26 Oct 2007 05:18:48 -0400 (EDT)
- References: <ffppu6$l6g$1@smc.vnet.net>
Gregory Lypny wrote:
> Hello everyone
>
> I've got an Nx4 numeric array called X. I'd like to pull out all
> rows where -9 does not appear in any of the four columns. I know I
> can this:
>
> Select[X, #[[1]] != -9 && #[[2]] != -9 && #[[3]] != -9 && #[[4]] !=
> -9 &]
>
> But is there a more elegant way that applies the not-equal-to
> condition to each column without having to repeat it?
if there are only integer numbers within your array, you can use:
Select[lst,FreeQ[#, -9] &]
to be on the save side, you might want to restrict FreeQ to look at the
entries at level 1 in the rows only:
Select[lst,FreeQ[#,-9,{1}]&]
the level restriction makes a difference in cases like:
lst={{a-9,5,6,3},{b[-9],0,-5,4}}
hth,
albert