r - 用于字符向量时匹配与魅力匹配

标签 r string match

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/

相关文章:

python - 从字符串中删除所有换行符

regex - 如何仅从特定位置删除字符串中的分隔符?

javascript - 嵌套在 if 语句中的函数

jquery - match() textarea 值然后将单词 append 到保持其原始顺序的 div

r - 从 GroupGrid 中抓取数据

php - 帮助解析 PHP 中的字符串

r - 基于另一列提取值

git - FaSTLane 匹配无法通过 SSH 连接

r - 更改基本几何图中的颜色

r - 使用 data.table 分配多个相互引用的变量