In R, match function for rows or columns of matrix

前端 未结 5 624
走了就别回头了
走了就别回头了 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条回答
  •  青春惊慌失措
    2020-12-31 23:49

    You could use apply:

    z <- apply(x, 1, function(a) apply(y, 1, function(b) all(a==b)))
    

    This will generate a matrix with nrow(x) rows and nrow(y) columns, whose entries mark the indices where there is a match.

提交回复
热议问题