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
} Articles by others on the same topic
There are currently no matching articles.