View source: R/matchMatrixLinesToRef.R
matchMatrixLinesToRef | R Documentation |
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.
matchMatrixLinesToRef(
mat,
ref,
exclCol = NULL,
addRef = TRUE,
inclInfo = FALSE,
silent = FALSE,
debug = FALSE,
callFrom = NULL
)
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) allows easier tracking of messages produced |
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.
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
match
, grep
, trimRedundText
, replicateStructure
## 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'
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.