Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

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

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

In article <8jc73k$dg3 at>, materialsscientist at 

> 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?


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]}


Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia                
Nedlands WA  6907                      

  • Prev by Date: Re: List of patterns for which a function is defined?
  • Next by Date: Re: Problems with Legendre expansion
  • Previous by thread: Getting number out of NDSolve
  • Next by thread: 3d-2d points