match
的文档和 charmatch
看起来几乎一模一样。当用于字符向量时,它们有什么区别吗?
最佳答案
charmatch
除了fixed
,还可以匹配partial匹配同时 match
只做一个固定的匹配。根据 ?charmatch
Exact matches are preferred to partial matches (those where the value to be matched has an exact match to the initial part of the target, but the target is longer).
If there is a single exact match or no exact match and a unique partial match then the index of the matching value is returned; if multiple exact or multiple partial matches are found then 0 is returned and if no match is found then nomatch is returned.
举个例子
charmatch('hell', c('hello', 'hellya'))
#[1] 0
charmatch('hell', c('hello', 'hel'))
#[1] 1
charmatch('hell', c('hello', 'hell'))
#[1] 2
match('hell', c('hello', 'hellya'))
#[1] NA
match('hell', c('hello', 'hel'))
#[1] NA
match('hell', c('hello', 'hell'))
#[1] 2
关于r - 用于字符向量时匹配与魅力匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61599675/