R语言 获取矢量中的元素匹配 – charmatch()函数
R编程语言 中的charmatch()函数 ,用于寻找两个参数之间的匹配。
语法: charmatch(x, table, nomatch = NA_integer_)
参数
- x: 要匹配的值
- table: 要匹配的值
- nomatch: 在非匹配位置要返回的整数值
r – charmatch() 函数示例
例1 :
# R program to illustrate
# charmatch function
# Calling the charmatch() function
charmatch("Geeks", c("Geeks", "forGeeks"))
charmatch("for", c("Geeks", "forGeeks"))
charmatch("forGeeks", c("Geeks", "forGeeks", "GeeksforGeeks"))
charmatch("GeeksforGeeks", c("Geeks", "forGeeks", "GeeksforGeeks"))
输出:
[1] 1
[1] 2
[1] 2
[1] 3
例2 :
# R program to illustrate
# charmatch function
# Calling the charmatch() function
charmatch("an", "sand")
charmatch("and", "sand")
charmatch("sand", "sand")
输出
[1] NA
[1] NA
[1] 1