function in R Language is used to return the positions of the first match of the elements of the first vector in the second vector. If the element is not found, it returns NA.**match()**

Syntax:match(x1, x2, nomatch)

Parameters:

x1:Vector 1

x2:Vector 2

nomatch:value to be returned in case of no match

**Example 1:**

`# R program to match the vectors ` ` ` `# Creating vectors ` `x1 <` `-` `c(` `"a"` `, ` `"b"` `, ` `"c"` `, ` `"d"` `, ` `"e"` `) ` `x2 <` `-` `c(` `"d"` `, ` `"f"` `, ` `"g"` `, ` `"a"` `, ` `"e"` `, ` `"k"` `) ` ` ` `# Calling match function ` `match(x1, x2) ` |

*chevron_right*

*filter_none*

**Output:**

[1] 4 NA NA 1 5

**Example 2:**

`# R program to match the vectors ` ` ` `# Creating vectors ` `x1 <` `-` `c(` `"a"` `, ` `"b"` `, ` `"c"` `, ` `"d"` `, ` `"e"` `) ` `x2 <` `-` `c(` `"d"` `, ` `"f"` `, ` `"g"` `, ` `"a"` `, ` `"e"` `, ` `"k"` `) ` ` ` `# Calling match function ` `match(x1, x2, nomatch ` `=` `"-1"` `) ` |

*chevron_right*

*filter_none*

**Output:**

[1] 4 -1 -1 1 5

## Recommended Posts:

- Seeking a unique match of elements in R Programming - char.expand() Function
- Compute the Covariance between Two Vectors in R Programming - cov() Function
- Compute the Correlation Coefficient Value between Two Vectors in R Programming - cor() Function
- Compute the Parallel Minima and Maxima between Vectors in R Programming - pmin() and pmax() Functions
- Getting Match of an Element within a Vector in R Programming - charmatch() Function
- Replace the First Match of a Pattern from a String in R Programming – sub() Function
- Seek a Match for the Pattern in the String in R Programming - pmatch() Function
- Getting and Setting Length of the Vectors in R Programming - length() Function
- Create a Data Frame of all the Combinations of Vectors passed as Argument in R Programming - expand.grid() Function
- Compute the beta value of Non-Negative Numeric Vectors in R Programming - beta() Function
- Generating sequenced Vectors in R Programming - sequence() Function
- Generate Color Vectors of desired Length in R Programming - rainbow() Function
- Matching of patterns in a String in R Programming - agrep() Function
- Creating a Data Frame from Vectors in R Programming
- Assigning Vectors in R Programming
- Types of Vectors in R Programming
- Append Operation on Vectors in R Programming
- Dot Product of Vectors in R Programming
- Cross Product of Vectors in R Programming
- String Matching in R Programming

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.