R语言 获取矢量中的元素匹配 – charmatch()函数

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"))
R

输出:

[1] 1
[1] 2
[1] 2
[1] 3
R

例2 :

# R program to illustrate
# charmatch function
 
# Calling the charmatch() function
charmatch("an", "sand")
charmatch("and", "sand")
charmatch("sand", "sand")
R

输出

[1] NA
[1] NA
[1] 1 
R

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册