获取矩阵元素坐标的函数

use*_*363 -1 r

我有矩阵A,我想得到它的元素坐标(row和col)给定该矩阵的元素.

我使用了哪个(A ==数字),但它没有给出给定元素的行和列号.我今天有什么想法我应该使用哪种功能?

> A
     [,1] [,2] [,3] [,4]
[1,]    1    6   11   16
[2,]    2    7   12   17
[3,]    3    8   13   18
[4,]    4    9   14   19
[5,]    5   10   15   20
Run Code Online (Sandbox Code Playgroud)

例如,对于给定的element = 18,我想得到coordinate:3, 4

Jil*_*ina 5

使用arr.ind=TRUE中which

> A <- matrix(1:20, ncol=4)
> which(A==18, arr.ind=TRUE)
     row col
[1,]   3   4
Run Code Online (Sandbox Code Playgroud)