In R, match function for rows or columns of matrix

前端 未结 5 607
走了就别回头了
走了就别回头了 2020-12-31 23:06

The value matching function in R is very useful. But from my understanding, it does not sufficiently support two or high dimensional inputs.

For examp

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-01 00:08

    match will work on lists of atomic vectors. So to match rows of one matrix to another, you could do:

    match(data.frame(t(x)), data.frame(t(y)))
    

    t transposes the rows into columns, then data.frame creates a list of the columns in the transposed matrix.

提交回复
热议问题