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]]
Ok so something like this. A 1 2 3 4 5 A v w x z G x z y w C y v z x D x v w z B 1 2 3 4 5 F z x y z D x z w v E x z w v So here I would just be comparing col 1. I would compare A[1,] to B[1,] and then I would see that A[1,4] has the same element as B[1,2], so I would remove A[,4]. Making A: A 1 2 3 4 5 A v w x z G x z y w C y v z x :) Cheers, Paul Research Technician Mass Spectrometry ? o The ? / o Scripps ? \ ? o Research ? / o Institute -----Original Message----- From: Leeds, Mark (IED) [mailto:Mark.Leeds at morganstanley.com] Sent: Wednesday, November 29, 2006 2:19 PM To: H. Paul Benton Subject: RE: [R] better define: matrix comparison and cbind issue paul : it honestly might be me ( seriously ) but you say 6th and 9th column but then You say A[9,x] and B[9,x] which are all the elements in the 9th row of A and 9th row of B respectively. Could you make 2 small sample matrices and the result matrix and explain it that way ? Honestly though, someone else may understand so maybe wait to see if someone else responds with an answer/suggestion. Good luck. -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of H. Paul Benton Sent: Wednesday, November 29, 2006 5:09 PM To: r-help at stat.math.ethz.ch Subject: [R] better define: matrix comparison and cbind issue 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. -------------------------------------------------------- This is not an offer (or solicitation of an offer) to buy/sell the securities/instruments mentioned or an official confirmation. Morgan Stanley may deal as principal in or own or act as market maker for securities/instruments mentioned or may advise the issuers. This is not research and is not from MS Research but it may refer to a research analyst/research report. Unless indicated, these views are the author's and may differ from those of Morgan Stanley research or others in the Firm. We do not represent this is accurate or complete and we may not update this. Past performance is not indicative of future returns. For additional information, research reports and important disclosures, contact me or see https://secure.ms.com/servlet/cls. You should not use e-mail to request, authorize or effect the purchase or sale of any security or instrument, to send transfer instructions, or to effect any other transactions. We cannot guarantee that any such requests received via e-mail will be processed in a timely manner. This communication is solely for the addressee(s) and may contain confidential information. We do not waive confidentiality by mistransmission. Contact me if you do not wish to receive these communications. In the UK, this communication is directed in the UK to those persons who are market counterparties or intermediate customers (as defined in the UK Financial Services Authority's rules).
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 columnthere> are ref numbers (molecular masses to be exact). I would like to check Aand> B by these columns. If I find that the number in A[9,x] and B[9, x] arethe> same then I want to remove the row that it is comparing from A. Sooverall,> 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 guidehttp://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?
So I guess I was thinking like a fuzzy if. I'm matching a number in my matrix and I would like to see if the numbers are the same to 0.1 accuracy. So in an if statement I would do something like: if(any((A[i,6] - B[j,6]) <= 0.1)) is this possible with match? Sorry for my lack of R knowledge. -----Original Message----- From: jim holtman [mailto:jholtman at gmail.com] Sent: Wednesday, November 29, 2006 7:17 PM To: H. Paul Benton Subject: Re: [R] better define: matrix comparison and cbind issue What do you mean by 'fuzzy'? If you want to compare multiple columns, you can compare each one separately and then use boolean AND/OR to combine them in whatever way you desire. col1 <- is.na(match(A[,1], B[,1])) col2 <- is.na(match(A[,2], B[,2])) A[col1 & col2,] # rows with no matches A[col1 | col2,] # rows with none or one match On 11/29/06, H. Paul Benton <hpbenton at scripps.edu> wrote:> Jim, > Is there a way to make match fuzzy? I had a look at ?match but > couldn't see anything about it so I thought I would as the guru. Also canI> do something like > index <- is.na(match(A[,1 & 2], B[,1 & 2])) > ? > > > index <- is.na(match(A[,1 & 2], B[,1 & 2])) > > index > [1] TRUE TRUE TRUE TRUE TRUE > > A[index,] > V1 V2 V3 V4 V5 > 1 A v w x z > 2 G x z y w > 3 C y v z x > 4 D x v w z > NA <NA> <NA> <NA> <NA> <NA> > > Thanks again, > > PB