In R, match function for rows or columns of matrix

前端 未结 5 612
走了就别回头了
走了就别回头了 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:56

    You could do that without using any functions:

    Suppose adj1 is the 3*3 matrix with both colnames and row.names being c('V1','V2','V3') and vec1 is the order you want your matrix to be transformed into:

    vec1 <- c('V2','V3','V1')
    

    You could simply using the following code:

    adj1[vec1,vec1]
    

    Which will do you the magic.

    Cheers!

提交回复
热议问题