Getting Match of an Element within a Vector in R Programming – charmatch() Function

charmatch() function in R Language is used to find matches between two arguments.

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

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# charmatch functiom
  
# 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"))

chevron_right


Output :

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

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

[1] NA
[1] NA
[1] 1
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.