# [R] Test for column equality across matrices

arun smartpink111 at yahoo.com
Sat Jul 13 19:35:28 CEST 2013

```Hi,
One way would be:
which(apply(t(B),1,paste,collapse="")%in%apply(t(A),1,paste,collapse=""))
#[1] 105 196 274 340 395
B[,105]
#[1]  1 15 16
B[,196]
#[1]  2 15 16
B1<-B[,!apply(t(B),1,paste,collapse="")%in%apply(t(A),1,paste,collapse="")]
dim(B1)
#[1]   3 555
dim(B)
#[1]   3 560

#or
B2<-B[,is.na(match(interaction(as.data.frame(t(B))),interaction(as.data.frame(t(A)))))]
identical(B1,B2)
#[1] TRUE

A.K.

----- Original Message -----
From: Thiem Alrik <thiem at sipo.gess.ethz.ch>
To: "mailman, r-help" <r-help at r-project.org>
Cc:
Sent: Saturday, July 13, 2013 9:45 AM
Subject: [R] Test for column equality across matrices

Dear list,

I have two matrices

A <- matrix(t(expand.grid(c(1,2,3,4,5), 15, 16)), nrow = 3)
B <- combn(16, 3)

Now I would like to exclude all columns from the 560 columns in B which are identical to any 1 of the 6 columns in A. How could I do this?

Many thanks and best wishes,

Alrik

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help