MathGroup Archive 2012

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

Search the Archive

Re: Extension to BinLists Function

Thank you Bob for your response to my problem.

I was unable to get a correct answer in exactly the way
you have formulated it.

When I do

breakPoints = {-Infinity, 2, 5, 7, Infinity}; 

data1 = {{1, 0.936229}, {3, 0.128096}, {2, 0.393583}, {1, 0.301525}, 
{4, 0.503822}, {5, 0.253597}, {6, 0.0835316}, {2, 0.0068356}}; 

BinLists[data1, {breakPoints}, {{-Infinity, Infinity}}] 

I get an error message which says:

Interpolation::indat: "Data point {-\[Infinity], 0} contains abscissa -\[Infinity], which is not a real number. 

And it suggests I click on a link whch redirects me to:
 ref/message/Interpolation/indat for further

I got around the Infinity problem in
the error message  by replacing the Infinity in both the breakPoints vector
and in {-Infinity, Infinity} with a number that is larger than any number
in data1 but which is still finite:

brkPts = {-100, 2, 5, 7, 100}

and then tried BinLists again:


which did work and produced:


But, I wanted to extend BinLists to being able to 
bin on any position in the data, not just the first element
of a sublist.

For example, if I wanted to bin on the second element 
in a sublist in data1, I don't see how to go about doing that
with the above technique.

Using the binLists function in my first post it would look like
the following:

brkPts = Range[.1, 1.0, .1]
binLists[data1,brkPts, {2}] 

which results in the following:


The third parameter, {2},  to binLists allows me to specify 
the element in a sublist of data1 which is to be used for binning,
no matter how complicated a sublist  is (assuming, of course,
that each sublist has the same structure).

For example,  if I wanted to bin
on the second element of the third element
in each sublist of data2 below, the
third input to binLists would be {3,2}:

data2={{1,0.936229, {2,.03}},{3,0.128096, {9,.73}},{2,0.393583, {4,.22}},{8,0.301525, {2,.18}},{1,0.503822, {6,.19}},{5,0.253597, {3,.20}},{6,0.0835316, {3,.29}},{2,0.0068356, {4,.81}}};

binLists[data2, brkPts2, {3,2}]

which results in


I don't see any way from the documentation to
get BinLists to do this as it does not take as input
the specification of the element position in the data
upon which binning is to occur, like {3,2} above.

The trouble with binLists, as  mentioned in the first post, is that
it is rather clumsy and depends on nested For loops
to do most of the work 
which, I assume from past experience, is quite slow
in terms of processor time.   I was
wondering if there is a faster, perhaps more elegant
way, to accomplis this.

Thank you.


  • Prev by Date: Re: SortBy won't order irrationals
  • Next by Date: Re: How to plot divergence of gradient as contour
  • Previous by thread: Re: Extension to BinLists Function
  • Next by thread: Re: Extension to BinLists Function