Re: Segregating the elements of a list based on given lower and upper bounds

*To*: mathgroup at smc.vnet.net*Subject*: [mg77265] Re: [mg77205] Segregating the elements of a list based on given lower and upper bounds*From*: János <janos.lobb at yale.edu>*Date*: Wed, 6 Jun 2007 07:04:02 -0400 (EDT)*References*: <200706051058.GAA01759@smc.vnet.net>

On Jun 5, 2007, at 6:58 AM, R.G wrote: > Hi Mathgroup members, > > Say, I have a list with the following elements: > > A={6.32553, 7.09956, 8.56784, 16.1871, 15.3989, 17.2285, 7.40711, \ > 14.8876, 19.9068, 10.0834} > > and I have the following list with each {xvalue, yvalue}={lower = bound, > upper bound}: > B={{0, 7}, {8, 10}, {11, 12}, {13, 15}, {16, 18}} > > How can I segregate values in A according to lower bound and upper > bound from B and find the number number of occurrence ?For example: > {0,7}={6.32553}, thus the number of occurrence is 1. > {8, 10}={7.09956,7.40711,8.56784}, the number of occurrence is 3. > {11,12}=None, the number of occurrence is 0. > > The code should be able work for any number Length[A] and Length[B]. > Any suggestion please? > Thank you, > R.G > Here is a newbie approach: /Your bounds do not correspond to the distribution you desire :)/ I use lower case a,b,c In[2]:= sa = Sort[a] In[4]:= c = Last[Reap[i = 1; While[i <= Length[sa], j = 1; While[j <= Length[b], If[b[[j,1]] <= sa[[i]] <= b[[j, 2]], Sow[{b[[j]], sa[[i]]}, j]; j++, j++; Continue[]]; ]* i++; ]]] Out[4]= {{{{0, 7}, 6.32553}}, {{{8, 10}, 8.56784}}, {{{13, 15}, 14.8876}}, {{{16, 18}, 16.1871}, {{16, 18}, 17.2285}}} =46rom there the distribution: In[22]:= ({#1[[1,1]], Length[ #1]} & ) /@ c Out[22]= {{{0, 7}, 1}, {{8, 10}, 1}, {{13, 15}, 1}, {{16, 18}, 2}} J=E1nos P.S Those ranges where you do not have a value you can Union it in with using Complement -------------------------------- "I wish developing great products was as easy as writing a check. If that were the case, Microsoft would have some great products." --Steve Jobs

**References**:**Segregating the elements of a list based on given lower and upper bounds***From:*"R.G" <gobiithasan@yahoo.com.my>