在 R 编程中获取向量中元素的匹配 –charmatch()函数
R 编程语言中的charmatch()函数 用于查找两个参数之间的匹配。
Syntax: charmatch(x, table, nomatch = NA_integer_)
Parameters:
- x: the values to be matched
- table: the values to be matched against
- nomatch: the integer value to be returned at non-matching position
r –charmatch()函数示例
示例 1:
R
# 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"))
R
# R program to illustrate
# charmatch function
# Calling the charmatch() function
charmatch("an", "sand")
charmatch("and", "sand")
charmatch("sand", "sand")
输出 :
[1] 1
[1] 2
[1] 2
[1] 3
示例 2:
R
# 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