[R] pairs matchning

Federico Calboli f.calboli at imperial.ac.uk
Thu Oct 26 18:47:49 CEST 2006


Hi All,

I have two numerical matrices of 2 columns and many rows.

The two coulumns of matrix (1) form a number of 'pairs' of numbers, e.g:

      [,1] [,2]
[1,]    1    0
[2,]    3    4
[3,]    3    4
[4,]    5    8
[5,]    1    0
[6,]    1    0
[7,]    6    7

Matrix (2) contains the *unique* pairs:

      [,1] [,2]
[1,]    1    0
[2,]    3    4
[3,]    5    8
[4,]    6    7


I would like to create a vector matching the pairs in matrix (1) to the unique 
pairs in matrix (2), e.g:

[1] 1 2 2 3 1 1 4

(done by hand)

match() does not seem to be able to handle pairs, and I don't seem to be able to 
find an elegant solution...

Cheers,

Federico

-- 
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place, London W2 1PG

Tel  +44 (0)20 7594 1602     Fax (+44) 020 7594 3193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com



More information about the R-help mailing list