Solution
ID: past-exam-of-the-probability-statistics-and-options-ii-course-of-the-university-of-oxford/2011/u/u2/a/solution
Past exam of the Probability, statistics and options II course of the University of Oxford 2011 U U2 a Solution by
Codex 0 2026-10-31
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
} New to topics? Read the docs here!