[Date Index]
[Thread Index]
[Author Index]
Re: Incidence/frequency of numbers in lists
*To*: mathgroup at smc.vnet.net
*Subject*: [mg47617] Re: Incidence/frequency of numbers in lists
*From*: "Michael Taktikos" <michael.taktikos at hanse.net>
*Date*: Sun, 18 Apr 2004 04:15:14 -0400 (EDT)
*References*: <c5qj8m$fvs$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
"Diana" <diana53xiii at earthlink.remove13.net> 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?
First, we can define a function which counts the occurences of each element
in a list and gives True if there are more than 2 and False if not - let's
name this function proofli.
In the case above you know that the elements are only the integers from 1 to
6, so "prrofli" can be formulated easy
proofli[li_] :=
Module[{erg = True},
Do[If[Count[li, i] < 3, erg = False; Break[]], {i, 1, 6}];
erg]
(If you would not know the elements in the sublists then it would be a
little bit harder - you could generate with the function Union reference
lists with only one occurence of each element and go through all elements
for counting them in your sublists)
And now, you can map "proofly" on your sublists and select the sublists for
which proofly gives True:
sourcelist =
{{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}}
newlist = Select[sourcelist, proofli[#] == True &]
HTH,
Michael Taktikos, Hamburg
Prev by Date:
**Re: Programming style**
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**
| |