Adam Warner
Adam Warner

Reputation: 1354

Keeping Duplicates With The Match Function

The code I am currently with is...

x <- c("1/1/1990",  "2/1/1990",  "3/1/1990",
       "4/1/1990",  "5/1/1990",  "6/1/1990",
       "7/1/1990",  "8/1/1990",  "9/1/1990",  "10/1/1990", 
       "11/1/1990") 
y <- c("1/1/1990","9/1/1990","1/1/1990","2/1/1990")
test <- match(x,y)
position <- which(test > 0)
position

The current output of position is:

[1] 1 2 9

I would like to keep the duplicate rows and have the output be..

[1] 1 1 2 9

Is this possible?

Thank you for your help.

Upvotes: 2

Views: 1891

Answers (1)

Pierre L
Pierre L

Reputation: 28451

Try this:

sort(match(y,x))
[1] 1 1 2 9

Upvotes: 5

Related Questions