Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.4K Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to bin non-scalar data?

Posted 10 years ago
POSTED BY: Virgile Andreani
5 Replies
Posted 10 years ago
Attachments:
POSTED BY: David Keith
Posted 10 years ago

You're welcome, Virgile. But I do think your BinListsBy would be good, or it would be nice if BinLists could accept an an optional level spec and a function to be applied to data elements before establishing bins and sorting the input into them. That way we would have the full capabilities of BinLists without the need to produce complicated functions for GatherBy.

POSTED BY: David Keith
Posted 10 years ago

It is also worth noticing that if the pairs consist of approximate numbers rounded values can be used to gather pairs whose first elements are close by some designed value:

In[4]:= realPairs = RandomReal[{1, 10}, {30, 2}]

Out[4]= {{5.21667, 6.47609}, {9.31783, 1.36685}, {1.64424, 
  5.90676}, {1.63877, 4.69312}, {8.20514, 9.13797}, {1.43469, 
  7.53501}, {7.32208, 7.86721}, {9.79302, 3.65095}, {3.37067, 
  1.09812}, {4.44002, 8.87933}, {2.05523, 8.75433}, {1.15523, 
  3.88057}, {1.87054, 2.36079}, {7.08747, 7.347}, {1.53206, 
  2.1205}, {6.06558, 6.74602}, {9.85321, 1.59023}, {8.23373, 
  8.98786}, {2.92257, 5.85836}, {4.70867, 9.13353}, {9.7615, 
  7.22106}, {2.21636, 5.98876}, {9.25288, 9.94328}, {8.56543, 
  6.00081}, {9.32182, 2.52546}, {2.91193, 3.88105}, {2.05716, 
  9.22982}, {2.02069, 6.72177}, {5.95095, 1.592}, {9.22202, 3.78433}}

In[6]:= GatherBy[realPairs, Round[#[[1]], .5] &]

Out[6]= {{{5.21667, 6.47609}}, {{9.31783, 1.36685}, {9.25288, 
   9.94328}, {9.32182, 2.52546}}, {{1.64424, 5.90676}, {1.63877, 
   4.69312}, {1.43469, 7.53501}, {1.53206, 2.1205}}, {{8.20514, 
   9.13797}, {8.23373, 8.98786}}, {{7.32208, 7.86721}}, {{9.79302, 
   3.65095}, {9.85321, 1.59023}, {9.7615, 7.22106}}, {{3.37067, 
   1.09812}}, {{4.44002, 8.87933}, {4.70867, 9.13353}}, {{2.05523, 
   8.75433}, {1.87054, 2.36079}, {2.21636, 5.98876}, {2.05716, 
   9.22982}, {2.02069, 6.72177}}, {{1.15523, 3.88057}}, {{7.08747, 
   7.347}}, {{6.06558, 6.74602}, {5.95095, 1.592}}, {{2.92257, 
   5.85836}, {2.91193, 3.88105}}, {{8.56543, 6.00081}}, {{9.22202, 
   3.78433}}}
POSTED BY: David Keith
POSTED BY: Virgile Andreani
Posted 10 years ago
POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard