【问题标题】:Coordinate matching matrix's in RR中的坐标匹配矩阵
【发布时间】:2018-05-18 14:11:09
【问题描述】:

目前我必须使用矩阵,并且我正在尝试返回它们在 z 中匹配的索引值? 这是我目前拥有的

           x y
matrixloc 0 0
          2 1
          2 3
          2 6
          5 5
          6 7
          4 9
> z
 x y
[1,] 2 6
[2,] 3 4
[3,] 5 5
[4,] 2 1
[5,] 2 3
[6,] 6 7  
[7,] 4 9
[8,] 6 8

目前我得到的输出是:

     match(matrixloc,z)
  NA  1  1  1  3  6  7 NA 12  2  6  3 14 15 

关于如何解决此问题的任何建议?

【问题讨论】:

标签: r indexing match


【解决方案1】:

这是在pasted 列条目上使用match 的一种(多种)方法

# Your sample data
matrixloc <- as.matrix(read.table(text =
    "x y
     0 0
     2 1
     2 3
     2 6
     5 5
     6 7
     4 9", header = T));
z <- as.matrix(read.table(text =
    "x y
     2 6
     3 4
     5 5
     2 1
     2 3
     6 7
     4 9
     6 8", header = T));

match(apply(matrixloc, 1, paste, collapse = "_"), apply(z, 1, paste, collapse = "_"));
#[1] NA  4  5  1  3  6  7

另外,“矩阵”的复数形式是“矩阵”,而不是“矩阵”。

【讨论】:

    猜你喜欢
    • 2013-06-20
    • 2020-02-11
    • 2016-08-05
    • 2018-04-15
    • 2015-12-26
    • 2017-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多