MathGroup Archive 2004

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

Search the Archive

Re: Incidence/frequency of numbers in lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47605] Re: [mg47599] Incidence/frequency of numbers in lists
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sun, 18 Apr 2004 04:15:02 -0400 (EDT)
  • References: <200404170631.CAA16308@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 17 Apr 2004, at 15:31, Diana wrote:

> Hi math folks,
>
> I have a 24 - 455 table. I have named the table SortedEdgeSet.
>
> The first few lines look like the following:
>
> {{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6,  
> 6},
> {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6,  
> 6},
> {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6,  
> 6},
> {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6,  
> 6},
> {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6,  
> 6},
> {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6,  
> 6},
> {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6,  
> 6},...
>
> The numbers 1 - 6 are listed 24 times in each of 455 sublists.
>
> I would like to create a new table which does not contain the sublist
> members which have two or fewer occurances of any of the six numbers  
> in the
> sublist. I only want sublists which have three or more of each of the
> numbers.
>
> So, for example, I would want to exclude the second sublist line:
>
> {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6,  
> 6},
> because it only has two 6's in it.
>
> I don't know what an occurance function might be in Mathematica. Can  
> anyone
> help?
>
> Thanks,
>
> Diana M.
> --  
> =====================================================
> "God made the integers, all else is the work of man."
> L. Kronecker, Jahresber. DMV 2, S. 19.
>
>
>
You don't need any "occurance" function (there is a function  
Frequencies in the Statistics`DataManipulation` package but it is not  
needed here).

If your sublists are already sorted, as in your example, then



ls={{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6,  
6, 6},
{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6,  
6},
{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6,  
6},
{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6,  
6},
{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6,  
6},
{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6,  
6},
{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6,  
6}};


Select[ls,Min[Length/@(Split[#])]>2&]


{{1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,5,5,5,6,6,6},{1,1,1,1,1,2,2,2,2,2, 
3,3,
     3,3,4,4,4,4,5,5,5,6,6,6},{
    
1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,5,5,5,5,6,6,6},{1,1,1,1,1,2,2,2,2,2,3, 
3,
     3,3,4,4,4,4,5,5,5,6,6,6},{
   1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,5,5,5,6,6,6,6}}

does the job. If not then you need to include Sort before split:

Select[ls,Min[Length/@(Split[Sort[#]])]>2&]


Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: Re: Incidence/frequency of numbers in lists
  • Next by Date: Re: Incidence/frequency of numbers in lists
  • Previous by thread: Re: Incidence/frequency of numbers in lists
  • Next by thread: Re: Incidence/frequency of numbers in lists