Seeking a unique match of elements in R Programming – char.expand() Function
Last Updated :
19 Apr, 2021
char.expand() function in R Language is used to seek a unique match of its first argument among the elements of its second. If successful, it returns this element; otherwise, it performs an action specified by the third argument.
Syntax: char.expand(input, target, nomatch = stop(“no match”))
Parameters:
input: character string to be expanded
target: character vector with the values to be matched against
nomatch: an R expression to be evaluated in case expansion was not possible
Example 1:
Python3
x < - c( "sand" , "and" , "land" )
char.expand( "a" , x, warning( "no expand" ))
char.expand( "an" , x, warning( "no expand" ))
char.expand( "and" , x, warning( "no expand" ))
|
Output :
[1] "and"
[1] "and"
[1] "and"
Example 2:
Python3
x < - c( "sand" , "and" , "land" )
char.expand( "G" , x, warning( "no expand" ))
|
Output:
[1] NA
Warning message:
In eval(nomatch) : no expand
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...