[R] searching for specific row in matrix

Esmail Bonakdarian esmail.js at gmail.com
Wed Jun 11 15:48:41 CEST 2008


Dimitris Rizopoulos wrote:
> try this:
> 
> match.pat <- function (mat, target, nomatch = -1) {
>    f1 <- do.call("paste", c(as.data.frame(mat), sep = "\r"))
>    f2 <- paste(target, collapse = "\r")
>    ind <- f1 %in% f2
>    if (any(ind)) which(ind)[1] else nomatch
> }

Thanks! More R for me to sink my teeth in :-)  My own solution
doesn't seem to work quite correctly as I found out from some
further testing .. so the solutions posted here are much appreciated!

Esmail



More information about the R-help mailing list