[R] Union of columns of two matrices

Johnson, Eric A. (Seattle) Eric.Johnson10 at va.gov
Thu Aug 7 01:42:28 CEST 2008


If a and b are your matrices of common row length, unique() can solve
it:

unique(cbind(a,b), MARGIN=2)

Eric



-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Giuseppe Paleologo
Sent: Wednesday, August 06, 2008 3:33 PM
To: r-help at r-project.org
Subject: [R] Union of columns of two matrices

I was posed the following problem/teaser:

given two matrices, come up with an "elegant" (=fast & short) function
that
returns a matrix with all and only the non-duplicated columns of both
matrices; the column order does not matter. In essence, a matrix
equivalent
of union(x,y), where x and y are vectors. I could not come with anything
nice. Any ideas?

Giuseppe

-- 
Giuseppe A. Paleologo :: Email: paleologo at gmail.com :: AOL: gappy3000 ::
Skype :: gappy3000 :: Gtalk: paleologo :: Mobile: 917.331.3497
fact: 2^32,582,657-1 is a prime

	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org 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