Re: identical rows in tables
- To: mathgroup at smc.vnet.net
- Subject: [mg97624] Re: [mg97583] identical rows in tables
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Tue, 17 Mar 2009 04:59:52 -0500 (EST)
- References: <200903160923.EAA25503@smc.vnet.net>
- Reply-to: drmajorbob at bigfoot.com
First the data: 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, 8, 7, 6, 5, 4, 3, 2}, {1, 8, 6, 7, 4, 5, 2, 3}, {1, 3, 2, 5, 4, 7, 6, 8}, {1, 3, 5, 2, 7, 4, 8, 6}}; Concatenating lists into strings: StringJoin @@@ (data /. q_Integer :> ToString@q) {"12345678", "14628375", "14263857", "13254768", "13527486", \ "18765432", "18674523", "13254768", "13527486"} or StringJoin @@@ Map[ToString, data, {2}] {"12345678", "14628375", "14263857", "13254768", "13527486", \ "18765432", "18674523", "13254768", "13527486"} Count copies: Tally@data Delete copies: DeleteDuplicates@data or Tally[data][[All,1]] or Union@data or DeleteDuplicates@(StringJoin @@@ Map[ToString, data, {2}]) {"12345678", "14628375", "14263857", "13254768", "13527486", \ "18765432", "18674523"} If you want colored strings: color[k_]:={Black,Red,Blue,Green}[[Mod[k,4,1]]] Tally[data]/.{x_List,k_}:>Style[StringJoin@@ToString/@x,color[k]] {12345678,14628375,14263857,13254768,13527486,18765432,18674523} (Execute the code, to see colors.) Bobby On Mon, 16 Mar 2009 04:23:48 -0500, King, Peter R <peter.king at imperial.ac.uk> 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). > > But in the following {{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, 8, > 7, 6, 5, 4, 3, 2}, {1, 8, 6, 7, 4, 5, 2, 3}, {1, 3, 2, 5, 4, 7, 6, > 8}, {1, 3, 5, 2, 7, 4, 8, 6},....} > > there is a pair {1, 3, 2, 5, 4, 7, 6, > 8}, {1, 3, 5, 2, 7, 4, 8, 6} which are the same. > > In an ideal world when I print out (in say TableForm) the repeated rows > ca= > n be printed in red (or some specified colour) > > These rows are permutations if that makes any difference. The tables can > be= > of any size (but always permutations of n numbers) > > as a subsidiary question is there an easy way to convert the tables into > nu= > mbers (or strings) eg > > {12345678,14628375,14263857 etc} > > Alternatively is there an easy way to perform permutations on strings of > ch= > aracters? > > Many thanks for your help to the multiple questions > ps I am using Mathematica 6.03 > -- DrMajorBob at bigfoot.com
- References:
- identical rows in tables
- From: "King, Peter R" <peter.king@imperial.ac.uk>
- identical rows in tables