pmatch 函数的性质 [英] Properties of pmatch function

查看:51
本文介绍了pmatch 函数的性质的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白内置函数 pmatch(部分字符串匹配)的行为.

I don't understand the behavior of the built-in function pmatch (partial string matching).

描述提供了以下示例:

pmatch("m",   c("mean", "median", "mode")) # returns NA instead of 1,2,3

但使用:

pmatch("m", "mean") # returns 1, as I would have expected. 

有人可以向我解释这种行为吗?

Could anybody explain to me this behavior?

推荐答案

根据文档:

nomatch:在不匹配或部分匹配的位置返回的值.请注意,它被强制为整数.

nomatch: the value to be returned at non-matching or multiply partially matching positions. Note that it is coerced to integer.

nomatch 默认为 NA(即,如果有多个部分匹配,则将返回 NA).

The nomatch defaults to NA (i.e., if there are multiple partial matches then NA will be returned).

pmatch("me",   c("mean", "median", "mode")) 
[1] NA  # returns NA instead of 1,2 since multiple partial matches

pmatch("mo",   c("mean", "median", "mode")) 
[1] 3   # since single partial match

这篇关于pmatch 函数的性质的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆