MathGroup Archive 2007

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

Search the Archive

Re: On partitioning lists by intervals

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80447] Re: On partitioning lists by intervals
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Wed, 22 Aug 2007 04:55:05 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <faea5n$ejf$1@smc.vnet.net>

Mauricio Esteban Cuak wrote:
<snip>
> I have a list of say 500 different random values. I need to divide it
> in n intervals of fixed length (for example, the lowest value is 0 and
> the maximum 100 so I need to get sublists of values that go from 0 to
> 10, 10 to 20, etc.)

One way to do that is with Select and Table, testing interval membership 
and sorting (if needed) the values. For instance,

In[1]:= data = RandomReal[{0, 100}, {50}];
data = Sort@data;
Table[Select[data, IntervalMemberQ[Interval[{m, m + 10}], #] &], {m,
   0, 90, 10}]

Out[3]= {{2.64545, 2.88612, 6.95366, 8.94619}, {}, {21.2125, 22.5317,
   23.3286, 23.5521, 27.0041, 27.0368}, {31.8472, 34.0783, 35.9797,
   38.0444}, {40.1175, 40.9223, 44.6731, 46.3196, 47.9082, 48.3849,
   49.7482}, {50.6901, 51.3209, 52.0433, 53.6529, 57.0734,
   59.8382}, {60.2186, 62.8556, 64.1785, 66.705, 68.0119,
   68.1914}, {70.2759, 73.2949, 75.0208, 75.026, 75.269, 76.8917,
   77.0392}, {80.4942, 85.8137, 87.242, 87.5028, 88.4888,
   89.8753}, {91.4804, 93.1612, 98.4789, 99.0704}}

-- 
Jean-Marc


  • Prev by Date: Re: Re: Cell Bracket Symbols
  • Next by Date: RE: Re: Missing information in Mathematica 6.0 Documentation
  • Previous by thread: Re: On partitioning lists by intervals
  • Next by thread: Re: On partitioning lists by intervals