MathGroup Archive 2005

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

Search the Archive

Re: Using Select with arrays? (Relative newbie)


Hi,

Select selects using a boolean function, Cases (which is what you want 
here) selects by pattern:

c=5;
d=6;
data={
{1,1,"string1",c,d} ,
{1,2,"string2",c,d} ,
{1,3,"string3",c,d} ,
{1,4,"string4",c,d} ,
{2,1,"string1",c,d} ,
{2,2,"string2",c,d} ,
{3,1,"string3",c,d},
{4,1,"string2",c,d} ,
{4,2,"string4",c,d}};

Cases[data, {1, _Integer, _String, _Integer, _Integer}]

{{1, 1, string1, 5, 4}, {1, 2, string2, 5, 4}, {
   1, 3, string3, 5, 4}, {1, 4, string4, 5, 4}}

Note - as written, your strings were not quoted and there were some 
commas missing - I guess just typos. Also, c and d required values - 
otherwise the pattern _Integer will not match. If this is a problem, 
just use the pattern _ in those positions, and it will match anything.

David Bailey
dbaileyconsultancy.co.uk


  • Prev by Date: Re: rules and lists
  • Next by Date: Re: rules and lists
  • Previous by thread: Re: Re: Re: Using Select with arrays? (Relative newbie)
  • Next by thread: Re: Using Select with arrays? (Relative newbie)