[R] better define: matrix comparison and cbind issue

Leeds, Mark (IED) Mark.Leeds at morganstanley.com
Thu Nov 30 03:01:56 CET 2006


Paul : I haven't tested this but try it and let me know. Let x be the #
of the col in A and y be the # of the column in B.

colinA<-A[,x]
colinB<-B[,y]

matchingrows<-B[(colinB %in% colinA),colinB]

C<-A[-1.0*c(matchingrows),]
 
I think C should be the resulting matrix that you want but it's untested
so check it. I'm notorious for missing unforeseen problems unless
I test things. When I have time later tonight, I'll test it myself.
Maybe someone else will help you now if it doesn't
work so I'll include the list.



-----Original Message-----
From: H. Paul Benton [mailto:hpbenton at scripps.edu] 
Sent: Wednesday, November 29, 2006 8:43 PM
To: 'jim holtman'; Leeds, Mark (IED)
Cc: r-help at stat.math.ethz.ch
Subject: RE: [R] better define: matrix comparison and cbind issue

Ok, so columns are fixed and my apologizes, for the incorrect
subscripting.
So I have the matching down because I'm matching a number so I've used
an if statement with some fuzz. At the moment my code from my earlier
post gets me a long vector with the data in it but not a nice matrix
that is readable.
Also this matrix is only the stuff which was found to be in both A and
B. I would like to get A - B as shown before. 
Cheers,

Paul

PS. Thx to mark, but don't miss your deadline.




----------
Mark wrote:
I understand better now but I just have 1 question and 1 comment.

1) how do you know  which columns to compare ? Is that fixed, like
parameters x an y where in the case below X = 1 and y = 1 ? Or does it
somehow depend on the matrix ?

2) your email was still really confusing because you are subscripting
incorrectly when you Refers to rows and columns. You have it backwards :
A[1,] is the first row.
A[,1] is the first column.

-----Original Message-----
From: jim holtman [mailto:jholtman at gmail.com]
Sent: Wednesday, November 29, 2006 2:40 PM
To: H. Paul Benton
Subject: Re: [R] better define: matrix comparison and cbind issue

match(a[9,], b[9,])

will tell you which elements in 'a' match 'b'

On 11/29/06, H. Paul Benton <hpbenton at scripps.edu> wrote:
> Hello,
>
> Sorry to all for the lack of communication, and thanks to those with 
> the suggestions.
>
> So I have two matrixes which are different sizes, same column number 
> but different row number.
>
> What I would like to do is to compare A to B. In the 6 and 9th column
there
> are ref numbers (molecular masses to be exact). I would like to check 
> A
and
> B by these columns. If I find that the number in A[9,x] and B[9, x] 
> are
the
> same then I want to remove the row that it is comparing from A. So
overall,
> if something appears in B then I remove it from A.
>
>
>
>            Cheers,
>
>
>
>            Paul
>
>
>
>
>
> Research Technician
>
> Mass Spectrometry
>
>   o The
>
>  /
>
> o Scripps
>
>  \
>
>   o Research
>
>  /
>
> o Institute
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>


--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?
--------------------------------------------------------

This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}



More information about the R-help mailing list