Message Boards Message Boards

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

How to bin non-scalar data?

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

You could use GatherBy:

(The pure function just presents the first part of each pair to GatherBy.)

In[2]:= pairs = RandomInteger[{1, 10}, {30, 2}]

Out[2]= {{8, 2}, {9, 6}, {7, 10}, {2, 4}, {9, 9}, {10, 2}, {8, 
  10}, {3, 1}, {10, 2}, {2, 4}, {8, 5}, {1, 1}, {2, 8}, {10, 9}, {10, 
  10}, {5, 7}, {4, 6}, {3, 6}, {1, 6}, {6, 10}, {2, 5}, {3, 4}, {8, 
  10}, {2, 10}, {10, 8}, {4, 8}, {1, 7}, {5, 4}, {6, 4}, {8, 10}}

In[3]:= GatherBy[pairs, #[[1]] &]

Out[3]= {{{8, 2}, {8, 10}, {8, 5}, {8, 10}, {8, 10}}, {{9, 6}, {9, 
   9}}, {{7, 10}}, {{2, 4}, {2, 4}, {2, 8}, {2, 5}, {2, 10}}, {{10, 
   2}, {10, 2}, {10, 9}, {10, 10}, {10, 8}}, {{3, 1}, {3, 6}, {3, 
   4}}, {{1, 1}, {1, 6}, {1, 7}}, {{5, 7}, {5, 4}}, {{4, 6}, {4, 
   8}}, {{6, 10}, {6, 4}}}
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

Group Abstract Group Abstract