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

MathGroup Archive 2009

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

Search the Archive

Re: identical rows in tables

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97635] Re: identical rows in tables
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Tue, 17 Mar 2009 05:01:58 -0500 (EST)

On 3/16/09 at 4:23 AM, peter.king at imperial.ac.uk (King, Peter R)
wrote:

>I have a table of values

>e.g.{{1, 2, 3, 4, 5, 6, 7, 8}, {1, 4, 6, 2, 8, 3, 7, 5}, {1, 4, 2,
>6, 3,
>8, 5, 7}, {1, 3, 2, 5, 4, 7, 6, 8}, {1, 3, 5, 2, 7, 4, 8, 6}, {1, 2,
>4, 3, 6, 5, 8, 7}, {1, 2, 3, 4, 5, 6, 7, 8}}

>and want to check if any rows are identical (so there are none in the
>above - I can remove last or first row which are supposed to be the
>same).

I normally use Union with Length to identify lists with
duplicates, i.e.

In[4]:= data = {{1, 2, 3, 4, 5, 6, 7, 8}, {1, 4, 6, 2, 8, 3, 7,
     5}, {1, 4, 2, 6, 3, 8, 5, 7}, {1, 3, 2, 5, 4, 7, 6, 8}, {1,
3, 5,
     2, 7, 4, 8, 6}, {1, 2, 4, 3, 6, 5, 8, 7}, {1, 2, 3, 4, 5,
6, 7,
     8}};

In[5]:= Length[data] == Length[Union@data]

Out[5]= False

indicating the presence of a duplicated item.

>In an ideal world when I print out (in say TableForm)  the repeated
>rows can be printed in red (or some specified colour)

Here is one way:

({#, Count[data, #]} & /@ data) /. {{a_, 1} :>
     Style[a, Black], {a_, b_} :> Style[a, Red]} // TableForm

>as a subsidiary question is there an easy way to convert the tables
>into numbers (or strings) eg

>{12345678,14628375,14263857 etc}

=46or numbers

=46romDigits /@ data

=46or strings

StringJoin@@@Map[ToString,data,{2}]



  • Prev by Date: Re: Different results with FourierTransform[]
  • Next by Date: Re: identical rows in tables
  • Previous by thread: Re: identical rows in tables
  • Next by thread: Re: identical rows in tables