[R] better define: matrix comparison and cbind issue

H. Paul Benton hpbenton at scripps.edu
Thu Nov 30 04:08:33 CET 2006


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 can I
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

-----Original Message-----
From: jim holtman [mailto:jholtman at gmail.com] 
Sent: Wednesday, November 29, 2006 6:19 PM
To: H. Paul Benton
Cc: Leeds, Mark (IED); r-help at stat.math.ethz.ch
Subject: Re: [R] better define: matrix comparison and cbind issue

Is this what you want?

> A <- read.table(textConnection("A v w x z
+ G x z y w
+ C y v z x
+ D x v w z
+ "), as.is=T)
>
> B <- read.table(textConnection("F z x y z
+ D x z w v
+ E x z w v
+ "), as.is=T)
>
> A
  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
> B
  V1 V2 V3 V4 V5
1  F  z  x  y  z
2  D  x  z  w  v
3  E  x  z  w  v
> # create logical vector of matching values
> index <- is.na(match(A[,1], B[,1]))
>
> 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
>
>
>
>
>


On 11/29/06, H. Paul Benton <hpbenton at scripps.edu> wrote:
> 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).
>
> ______________________________________________
> 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?



More information about the R-help mailing list