Compare every complete row with the given vector, returning as soon as a match is found. The length check prevents recycling of the vector; seq_len also handles an empty matrix correctly. This implementation treats a missing comparison as a nonmatch and always returns a Boolean.
row.match <- function(X, y) {
  stopifnot(is.matrix(X), length(y) == ncol(X))
  for (i in seq_len(nrow(X))) {
    eq <- X[i, ] == y
    if (all(!is.na(eq) & eq)) return(TRUE)
  }
  FALSE
}
For the integer-coordinate matrices used below there are no missing values, so this is ordinary exact row equality.

Articles by others on the same topic (0)

There are currently no matching articles.