MathGroup Archive 2002

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

Search the Archive

Re: Help with Select[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34647] Re: Help with Select[]
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Fri, 31 May 2002 04:26:23 -0400 (EDT)
  • References: <ad4j0u$jkt$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Kevin:

    mySelect[m_]:= Cases[m,{{_,0}...}]

Check:

    setA={{{x1,0},{x2,0}},{{x3,0},{x4,0}},{{x5,1},{x6,0}},{{x7,1},{x8,1}}};

    setB={{{x1,0},{x2,0},{x3,0}},{{x4,0},{x5,0},{x6,0}},{{x7,1},{x8,0},{x9,
          1}},{{x10,1},{x11,1},{x12,0}}};

    mySelect[setA]

        {{{x1,0},{x2,0}},{{x3,0},{x4,0}}}

    mySelect[setB]

        {{{x1,0},{x2,0},{x3,0}},{{x4,0},{x5,0},{x6,0}}}

--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"Kevin Gross" <kc144_nospam at ameritech.net> wrote in message
news:ad4j0u$jkt$1 at smc.vnet.net...
> Hello all,
>
> I've got data sets that resemble
>
> setA={
> {{x1,0},{x2,0}},
> {{x3,0},{x4,0}},
> {{x5,1},{x6,0}},
> {{x7,1},{x8,1}}
> };
>
> setB={
> {{x1,0},{x2,0},{x3,0}},
> {{x4,0},{x5,0},{x6,0}},
> {{x7,1},{x8,0},{x9,1}},
> {{x10,1},{x11,1},{x12,0}}
> };
>
> Each element of the set is a list of n (x,y) ordered pairs. So n=2 for the
> first set and n=3 for the second set. In general, n will differ between
the
> data sets, but can be known. With each set, I want to select those
elements
> whose sub-elements all have y=0. This is hard to explain in English, but
> easy to express in Mathematica:
>
> In:  Select[setA,(#[[1,2]]==#[[2,2]]==0)&]
> Out: {{{x1,0},{x2,0}},{{x3,0},{x4,0}}}
>
> In:  Select[setB,(#[[1,2]]==#[[2,2]]==#[[3,2]]==0)&]
> Out: {{{x1,0},{x2,0},{x3,0}},{{x4,0},{x5,0},{x6,0}}}
>
> First, I would like to know how to generate an arbitrary "selection
> function" f[n] so that
>
> In: Select[setC,f[8]]
> Out: {{{x1,0},...,{x8,0}},{{x9,0},...,{x16,0}},...}
>
> Is it possible to construct such an f? Or is there a better way of
> accomplishing this task? It seems that perhaps pattern matching might be
of
> use, but I haven't gotten too far with it.
>
> Thanks in advance,
>
> Kevin Gross
>
>




  • Prev by Date: RE: Help with Select[]
  • Next by Date: RE: new user question about creating a new cell
  • Previous by thread: RE: Help with Select[]
  • Next by thread: Re: How write or Export a Cell holding a Matrix in //MatrixForm format