Re: Delete problem
- To: mathgroup at smc.vnet.net
- Subject: [mg52904] Re: [mg52871] Delete problem
- From: William K Reinholtz <kirk.reinholtz at jpl.nasa.gov>
- Date: Thu, 16 Dec 2004 03:40:51 -0500 (EST)
- References: <200412150926.EAA10676@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Todd:
Your problem is begging for the application of the Mathematica pattern
matching capabilities. For example:
Cases[masterlist,{{a_,_,_,_,_,_,_,_,p1_},{a_,_,_,_,_,_,_,_,
p2_},{a_,_,_,_,_,_,_,_,p3_}} /;
Abs[Plus@@Sign[{p1,p2,p3}]] == 3]
The above will select exactly the "groups" with three elements, all
with the same first member, and all with the same sign in the 9th
member. Take a look at Position[] and Extract[] and you'll see some
great ways to quickly do what you wish.
By the way it might be a bit obscure as to why the first members must
match in the above. It turns out that if a pattern with the same name
is mentioned several places in a larger pattern (e.g. "a_" above) then
Mathematica will only match where each pattern has the same exact matched value.
It's difficult to get this from the help pages.
Important: You must quote the first item in each list, e.g.
"AEST-01-C-10" or Mathematica will evaluatate it as an expression.
There are other ways to prevent such evaluation as well (e.g. via the
use of Hold[]) but they're trickier to use.
On Dec 15, 2004, at 1:26 AM, Todd Allen wrote:
> masterlist={{{AEST-01-C-10,1,1,1,2,31,1,C,-2.14},{AEST-01-C
> -10,1,1,1,4,31,1,
>
> C,-1.1},{AEST-01-C-10,2,2,1,2,12,2,C,1.79}},{{AEST-07-E
> -04,2,1,2,1,10,2,
>
> C,1.334},{AEST-07-E-04,2,1,3,2,1,4,C,1.997},{AEST-07-E-04,3,2,1,1,2,1,
> C,-1.17},{AEST-07-E-04,3,4,1,1,21,2,C,2.15}}};
>
> index=1;ccheck=Sign[masterlist[[index,All,9]]];While[
> index<=Length[masterlist],
> If[Count[ccheck,_?Positive]>0 &&
> Count[ccheck,_?Negative]>0 &&
>
> Count[ccheck,_Integer]==3,masterlist=Delete[masterlist,index],index++]]
> ;
- References:
- Delete problem
- From: Todd Allen <genesplicer28@yahoo.com>
- Delete problem