Re: [R] Return "TRUE" only for first match of values between matrix and vector.

2014-05-03 Thread arun
Hi, This should be little more faster. indx <- A==B indx1 <- which(indx, arr.ind=TRUE) indx[indx1[duplicated(indx1[,1]),]]<- FALSE indx ##Speed comparison ##previous method fun1 <- function(mat, vec) {     stopifnot(dim(mat)[1] == length(vec))     indx <- mat == vec     t(apply(indx, 1, functio

Re: [R] Return "TRUE" only for first match of values between matrix and vector.

2014-05-02 Thread Jorge I Velez
Hi Nevil, Try apply(A, 2, function(x) x == B) HTH, Jorge.- On Fri, May 2, 2014 at 6:46 PM, nevil amos wrote: > I wish to return " True" in a matrix for only the first match of a value > per row where the value equals that in a vector with the same number of > values as rosw in the matrix >

Re: [R] Return "TRUE" only for first match of values between matrix and vector.

2014-05-02 Thread arun
Hi, Try: indx <- A==B t(apply(indx,1,function(x) {x[duplicated(x) & !is.na(x)] <- FALSE; x})) #  [,1]  [,2]  [,3] #[1,]  TRUE FALSE FALSE #[2,] FALSE    NA FALSE #[3,]    NA    NA    NA #[4,]  TRUE    NA FALSE #[5,] FALSE  TRUE FALSE A.K. On Friday, May 2, 2014 4:47 AM, nevil amos wrote:

[R] Return "TRUE" only for first match of values between matrix and vector.

2014-05-02 Thread nevil amos
I wish to return " True" in a matrix for only the first match of a value per row where the value equals that in a vector with the same number of values as rosw in the matrix eg: A<-matrix(c(2,3,2,1,1,2,NA,NA,NA,5,1,0,5,5,5),5,3) B<-c(2,1,NA,1,5) desired result: [,1] [,2] [,3] [1,] TRUE FA