MathGroup Archive 2010

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

Search the Archive

Re: BinLists in Array

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111597] Re: BinLists in Array
  • From: Darren Glosemeyer <darreng at wolfram.com>
  • Date: Sat, 7 Aug 2010 01:30:01 -0400 (EDT)

Murta wrote:
> Hello All
>
>    I Would like to split this array: l={{1, 0}, {1, 1}, {1, 2}, {2,
> 3}, {2, 4}}, by the second element of each group, to group what are
> between 0-2, 2-4,4-6 and so on (just the second element)
>    Using BinLists look like a good idea. I get my desirable result
> with:
>        BinLists[{{1, 0}, {1, 1}, {1, 2}, {2, 3}, {2, 4}}, {0, 10, 10},
> {0, 10, 2}]
>
>   But I would like to don't have to put any struction to the first
> element (the "{0, 10, 10}" information)
>   How I can ignore it? I tried something like
>        BinLists[{{1, 0}, {1, 1}, {1, 2}, {2, 3}, {2, 4}},None, {0, 10,
> 2}]
>        BinLists[{{1, 0}, {1, 1}, {1, 2}, {2, 3}, {2, 4}},Automatic,
> {0, 10, 2}]
>        BinLists[{{1, 0}, {1, 1}, {1, 2}, {2, 3}, {2, 4}},All, {0, 10,
> 2}]
>   But isn't the way.
>
> Thanks in advande
> Murta
>   

I assume the main issue is not having to look at the data to determine 
what the range should be to capture all the data values in that 
particular coordinate. You could use the allSpec function that follows 
to construct a specification that captures all values in the i^th column 
of the data without manually constructing it.

In[1]:= allSpec[dataset_, i_] :=
         With[{min = Min[dataset[[All, i]]], max = Max[dataset[[All, i]]]},
          {min - 1, max + 1, max - min + 2}]

In[2]:= data = {{1, 0}, {1, 1}, {1, 2}, {2, 3}, {2, 4}};

In[3]:= BinLists[data, allSpec[data, 1], {0, 10, 2}]

Out[3]= {{{{1, 0}, {1, 1}}, {{1, 2}, {2, 3}}, {{2, 4}}, {}, {}}}


Darren Glosemeyer
Wolfram Research


  • Prev by Date: Re: classroom combinatorics
  • Next by Date: Re: Nonlinear fitting question
  • Previous by thread: Re: BinLists in Array
  • Next by thread: Re: BinLists in Array