Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Creating sub-list based on a given criterion

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110573] Creating sub-list based on a given criterion
  • From: Dimitris Emmanoulopoulos <demmanoulopoulos at hotmail.com>
  • Date: Sat, 26 Jun 2010 03:10:35 -0400 (EDT)

Hello

I was wondering if there is any straightforward way to bin a list into sub-lists containing those elements that full-fill a given criterion. Consider the following list

ds=
{{{0,0,1},{1,0,-1},{2,0,-1},{3,0,-1},{4,0,-1},{5,588,-1},{6,2345,1},{7,2418,1},{8,2323,1},{9,2179,1}},{{480,23,1},{487,23,1},{470,29,1},{478,32,1},{468,25,1},{498,19,-1},{494,15,1},{496,20,1},{455,33,1},{462,27,1}},{{781,1,1},{779,1,1},{784,0,1},{778,0,1},{766,1,-1},{735,1,-1},{758,1,-1},{733,2,-1},{716,0,-1},{794,1,1}}}

The criterion is that the sum of the second elements in each new sub-list should be at least 25?

After the re-binning we should get something like:

{{0,0,1},{1,0,-1},{2,0,-1},{3,0,-1},{4,0,-1},{5,588,-1}}
{6,2345,1}
{7,2418,1}
{8,2323,1}
{9,2179,1}
{{480,23,1},{487,23,1}}
{470,29,1}
{478,32,1}
{468,25,1},
{498,19,-1},{494,15,1},
{496,20,1},{455,33,1}
{{462,27,1},{781,1,1},{779,1,1},{784,0,1},{778,0,1},{766,1,-1},{735,1,-1},{758,1,-1},{733,2,-1},{716,0,-1},{794,1,1}}}

The first bin has a total of the second elements 588, the second 2345, the third 2418,...,the sixth 46, the seventh 29, â?¦,the eleventh 53, and the last one 35.

In other words, imagine that these are the results of a counting experiment and the second element in every entry (in  ds) corresponds to counts. The question is how can we re-bin the data in order to have at least 25 counts per new-bin?
Of course it is straightforward to do it using a Do-loop, but I was wondering if there is any simpler way to do it using the efficient Mathematica syntax in an â??one-liner expressionâ??.

Thanks a lot
Dimitris


  • Prev by Date: Re: precedence for ReplaceAll?
  • Next by Date: how to automatically include own package into different demonstration
  • Previous by thread: Orthogonalize in a discrete setting
  • Next by thread: Re: Creating sub-list based on a given criterion