Solution

ID: past-exam-of-the-probability-statistics-and-options-ii-course-of-the-university-of-oxford/2011/u/u2/a/solution

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.

New to topics? Read the docs here!