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

• To: mathgroup at smc.vnet.net
• Subject: [mg24173] Re: Need to reduce 2 lists so that only {x,y} pairs with same x remain
• From: Harald Giese <giese at ifm.uni-hamburg.de>
• Date: Wed, 28 Jun 2000 22:50:54 -0400 (EDT)
• Organization: Institut fuer Meereskunde, Universitaet Hamburg
• References: <8jc73k\$dg3@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```materialsscientist at my-deja.com wrote:
>
> Hello,
>
> 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?
>

Hi Chuck,

Try this:

pos1in2 = Position[First /@ data1, #] & /@ (First /@ data2) // Flatten
newdata1 = data1[[pos1in2]]

pos2in1 = Position[First /@ data2, #] & /@ (First /@ data1) // Flatten
newdata2 = data2[[pos2in1]]

Regards,
Harald

--

Harald Giese
Email: giese at dkrz.de
Phone: +49 (0)40 42838 5796; Fax: +49 (0)40 5605724
Institut fuer Meereskunde der Universitaet Hamburg
(Institute of Oceanography of the University of Hamburg)
Troplowitzstrasse 7, D-22529 Hamburg

```

• Prev by Date: Re: Integration...
• Next by Date: Re: AIX 4.3 Mathematica MathKernel Out of Memory
• Previous by thread: Re: Need to reduce 2 lists so that only {x,y} pairs with same x remain
• Next by thread: RE: Need to reduce 2 lists so that only {x,y} pairs with same x remain