[R] pairs matchning

Ben Fairbank BEN at SSANET.COM
Thu Oct 26 18:47:28 CEST 2006


If all of the numbers are one-digit numbers, as your subset shows, you
can create a third column equal to 10 * col 1 + col 2, and then use
match() on the resulting two-digit numbers, no?  If the numbers are
larger than one-digit, and you know the maximum, use that rather than 10
as the multiplier.

Ben

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Federico Calboli
Sent: Thursday, October 26, 2006 11:48 AM
To: r-help
Subject: [R] pairs matchning

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

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list