matMatch: Matching of matrices

View source: R/auxiliary.R

matMatchR Documentation

Matching of matrices

Description

Wrapper for matching a matrix against another, by rows or columns.

Usage

matMatch(x, mat, rows = TRUE, useMatch = FALSE, ...)

Arguments

x

matrix with the values to be matched.

mat

matrix with the values to be matched against.

rows

whether the match should be done by rows (TRUE) or columns (FALSE).

useMatch

whether to rely on match or not. Might give unexpected mismatches due to working with lists.

...

further parameters passed to match.

Value

An integer vector of length nrow(x) (or ncol(x)) giving the row (or col) position in table of the first match, if there is a match.

Examples

# By rows
A <- rbind(5:6, repRow(1:2, 3), 3:4)
B <- unique(A)
ind <- matMatch(x = A, mat = B)
A
B[ind, ]

# By columns
A <- cbind(5:6, repCol(1:2, 3), 3:4)
B <- t(unique(t(A)))
ind <- matMatch(x = A, mat = B, rows = FALSE)
A
B[, ind]

egarpor/sdetorus documentation built on March 4, 2024, 1:23 a.m.