📜  在 R 编程中寻找元素的独特匹配 – char.expand()函数

📅  最后修改于: 2022-05-13 01:55:29.012000             🧑  作者: Mango

在 R 编程中寻找元素的独特匹配 – char.expand()函数

R 语言中的char.expand()函数用于在第二个参数的元素中寻找其第一个参数的唯一匹配。如果成功,则返回此元素;否则,它执行第三个参数指定的动作。

示例 1:

Python3
# R program to illustrate
# char.expand function
 
# Creating string vector
x <- c("sand", "and", "land")
 
# Calling char.expand() function
char.expand("a", x, warning("no expand"))
char.expand("an", x, warning("no expand"))
char.expand("and", x, warning("no expand"))


Python3
# R program to illustrate
# char.expand function
 
# Creating string vector
x <- c("sand", "and", "land")
 
# Calling char.expand() function
char.expand("G", x, warning("no expand"))


输出 :

[1] "and"
[1] "and"
[1] "and"

示例 2:

Python3

# R program to illustrate
# char.expand function
 
# Creating string vector
x <- c("sand", "and", "land")
 
# Calling char.expand() function
char.expand("G", x, warning("no expand"))  

输出:

[1] NA
Warning message:
In eval(nomatch) : no expand