The match() function used to find first position of element in a vector,list or data frame in R.

The following method shows how you can do it with syntax.

Method: Use match() Function

match(x,list)

x: The element whose position want to find.

The following example shows how to use match() function in R:

Use match() Function to Find Position of Element from Vector

Let’s see how we can find element position from vector using match() function:

# Define value
x <-12

# Define vector
vector1 <-c(45,85,89,78,12,36,68,32,12)

# Find first position of 12 in vector
match(x,vector1)

Output:

[1] 5

As the output shows first index position of 12 is 5 in vector.

The match() function returns the position of the first match, or NA if no match is found.