Re: Extension to BinLists Function

*To*: mathgroup at smc.vnet.net*Subject*: [mg124048] Re: Extension to BinLists Function*From*: Don <donabc at comcast.net>*Date*: Sat, 7 Jan 2012 05:19:07 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com

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 explanation. 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: BinLists[data1,{brkPts},{{-100,100}}] which did work and produced: {{{{1,0.936229},{1,0.301525}}},{{{3,0.128096},{2,0.393583},{4,0.503822},{2,0.0068356}}},{{{5,0.253597},{6,0.0835316}}},{{}}} 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: {{{6,0.0835316},{2,0.0068356}},{{3,0.128096}},{{5,0.253597}},{{2,0.393583},{1,0.301525}},{},{{4,0.503822}},{},{},{},{{1,0.936229}},{}} 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 {{{1,0.936229,{2,0.03}}},{{8,0.301525,{2,0.18}},{1,0.503822,{6,0.19}}},{{2,0.393583,{4,0.22}},{5,0.253597,{3,0.2}},{6,0.0835316,{3,0.29}}},{},{},{},{},{{3,0.128096,{9,0.73}}},{{2,0.0068356,{4,0.81}}},{},{}} 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. Don

**Follow-Ups**:**Re: Extension to BinLists Function***From:*Bob Hanlon <hanlonr357@gmail.com>

**Re: SortBy won't order irrationals**

**Re: How to plot divergence of gradient as contour**

**Re: Extension to BinLists Function**

**Re: Extension to BinLists Function**