Learn R Programming

sdetorus (version 0.1.10)

matMatch: Matching of matrices

Description

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

Usage

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

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.

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.

Examples

Run this code
# 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]

Run the code above in your browser using DataLab