Re: Need to reduce 2 lists so that only {x,y} pairs with same x remain

*To*: mathgroup at smc.vnet.net*Subject*: [mg24459] Re: Need to reduce 2 lists so that only {x,y} pairs with same x remain*From*: Paul Abbott <paul at physics.uwa.edu.au>*Date*: Tue, 18 Jul 2000 00:59:03 -0400 (EDT)*Organization*: University of Western Australia*References*: <8jc73k$dg3@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

In article <8jc73k$dg3 at smc.vnet.net>, materialsscientist at my-deja.com wrote: > I have 2 lists of data: > > for example > data1={{1,1},{1.5,1.5},{2,2},{3,3},{4,4},{5,5}} > > data2={{1,2},{2,3},{3,4},{4,5},{6,7},{7,8}} > > > I want to do a point by point comparision, so I > need to reduce both data1 and data2 so that > common x data in the {x,y} pairs for each list > remain. > > Thus the lists should look like this: > > data1={{1,1},{2,2},{3,3},{4,4}} > data2={{1,2},{2,3},{3,4},{4,5}} > > What function(s) would to something like this? data1={{1,1},{1.5,1.5},{2,2},{3,3},{4,4},{5,5}} data2={{1,2},{2,3},{3,4},{4,5},{6,7},{7,8}} You are basically after the Intersection of the (common x data) of two sets. You can use the SameTest option: SetOptions[Intersection, SameTest -> (#1[[1]] == #2[[1]] & )]; and then {data1, data2} = {Intersection[data1, data2], Intersection[data2, data1]} Cheers, Paul -- Paul Abbott Phone: +61-8-9380-2734 Department of Physics Fax: +61-8-9380-1014 The University of Western Australia Nedlands WA 6907 AUSTRALIA http://physics.uwa.edu.au/~paul