Get the index of the values of one vector in another?

后端 未结 2 428
孤街浪徒
孤街浪徒 2020-12-05 18:05

I would guess this is a duplicate, but I can\'t find that so here goes...

I\'d like to return the index of second in first:

first = c( \"a\" , \"c\"          


        
2条回答
  •  攒了一身酷
    2020-12-05 18:32

    Getting indexes of values is what match() is for.

     first = c( "a" , "c" , "b" )
     second = c( "c" , "b" , "a" )
     match(second, first)
     [1] 2 3 1
    

提交回复
热议问题