matchMatrixLinesToRef {wrMisc} | R Documentation |
Match All Lines of Matrix To Reference Note
Description
This function allows adjusting the order of lines of a matrix mat
to a reference character-vector ref
,
even when initial direct matching of character-strings using match
is not possible/successful.
In this case, various variants of using grep
will be used to see if unambiguous matching is possible of characteristic parts of the text.
All columns of mat
will be tested an the column giving the bes resuts will be used.
Usage
matchMatrixLinesToRef(
mat,
ref,
exclCol = NULL,
addRef = TRUE,
inclInfo = FALSE,
silent = FALSE,
debug = FALSE,
callFrom = NULL
)
Arguments
mat |
(matrix or data.frame) main input, all columns of |
ref |
(character, length must match ) reference for trying to match each of the columns of |
exclCol |
(character or integer) column-name or -index of column to ignore/exclude when looking for matches |
addRef |
(logical), if |
inclInfo |
(logical) allows returning list with new matrix and additional information |
silent |
(logical) suppress messages |
debug |
(logical) additional messages for debugging |
callFrom |
(character) allow easier tracking of messages produced |
Details
This function tests all columns of mat
to find perfect matching results to the reference ref
.
In case of multiple results the
In case no direct matching is possible, grep
will be used to find the best partial matching.
The orderof the rows of input mat
will be adjusted according to the matching results.
If addRef=TRUE
, the reference will be included as additional column to the results, too.
Value
This function returns the input matrix in an adjusted order (plus an optional additional column showing the reference)
or if inclInfo=TRUE
a list with $mat (adjusted matrix), $byColumn, $newOrder and $method;
the reference can bee added as additional last column if addRef=TRUE
See Also
match
, grep
, trimRedundText
, replicateStructure
Examples
## Note : columns b and e allow non-ambigous match, not all elements of e are present in a
mat0 <- cbind(a=c("mvvk","axxd","bxxd","vv"),b=c("iwwy","iyyu","kvvh","gxx"), c=rep(9,4),
d=c("hgf","hgf","vxc","nvnn"), e=c("_vv_","_ww_","_xx_","_yy_"))
matchMatrixLinesToRef(mat0[,1:4], ref=mat0[,5])
matchMatrixLinesToRef(mat0[,1:4], ref=mat0[1:3,5], inclInfo=TRUE)
matchMatrixLinesToRef(mat0[,-2], ref=mat0[,2], inclInfo=TRUE) # needs 'reverse grep'