Re: [R] searching for specific row in matrix

From: Esmail Bonakdarian <esmail.js_at_gmail.com>
Date: Wed, 11 Jun 2008 09:48:41 -0400

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



R-help_at_r-project.org 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. Received on Wed 11 Jun 2008 - 15:36:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 11 Jun 2008 - 16:30:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive