Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 从内容中查找矩阵中单元格的位置_R_Matrix_Cell - Fatal编程技术网

R 从内容中查找矩阵中单元格的位置

R 从内容中查找矩阵中单元格的位置,r,matrix,cell,R,Matrix,Cell,非常基本的问题,但我找不到答案 对于一般矩阵(在我的例子中,我有一个邻接矩阵,如下所示,但要大得多): 我计算了邻接矩阵中值的频率 table <- data.frame(table(as.matrix(n))) 表任意邻接矩阵n: n <- as.matrix(rbind(c(1,0.2,0.8,0.6), c(0.3,1,0.8,0.2), c(0.8,0.1,1,0.3), c(0

非常基本的问题,但我找不到答案

对于一般矩阵(在我的例子中,我有一个邻接矩阵,如下所示,但要大得多):

我计算了邻接矩阵中值的频率

table <- data.frame(table(as.matrix(n)))

表任意邻接矩阵n:

n <- as.matrix(rbind(c(1,0.2,0.8,0.6),
                c(0.3,1,0.8,0.2),
                c(0.8,0.1,1,0.3),
                c(0.8,0.2,0.3,1)))
输出:

     row col
[1,]   3   1
[2,]   4   1
[3,]   1   3
[4,]   2   3

OP肯定在寻找哪个
。尽管如此,作为一个例子,我还是避免使用带有浮点值的矩阵。我们需要记住,必须避免浮点值之间的精确比较(例如,请参阅)。最好使用整数。
value = 0.8
which(n == value, arr.ind=T)
     row col
[1,]   3   1
[2,]   4   1
[3,]   1   3
[4,]   2   3