[R] better define: matrix comparison and cbind issue
H. Paul Benton
hpbenton at scripps.edu
Thu Nov 30 04:29:00 CET 2006
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 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
More information about the R-help
mailing list