Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.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 - Fatal编程技术网

R 如何获取矩阵的有序数据索引?

R 如何获取矩阵的有序数据索引?,r,R,要求很简单。例如,我们可以得到如下矩阵: n "matix" > d [,1] [,2] [1,] 1 3 [2,] 2 4 我想获得d的有序数据的索引,例如: (2,2) (1,2) (2,1) (1,1) 我认为R必须有一个函数来做这项工作。有人知道吗?谢谢。您可以使用order()对单元格进行排序,然后使用arrayInd获取索引 d<-matrix(1:4, nrow=2) arrayInd(order(d, decreasing=T),

要求很简单。例如,我们可以得到如下矩阵:

n "matix"
> d
     [,1] [,2]
[1,]    1    3
[2,]    2    4
我想获得d的有序数据的索引,例如:

(2,2)
(1,2)
(2,1)
(1,1)
我认为R必须有一个函数来做这项工作。有人知道吗?谢谢。

您可以使用
order()
对单元格进行排序,然后使用
arrayInd
获取索引

d<-matrix(1:4, nrow=2)
arrayInd(order(d, decreasing=T), .dim=dim(d))

#      [,1] [,2]
# [1,]    2    2
# [2,]    1    2
# [3,]    2    1
# [4,]    1    1
d您可以使用
order()
对单元格进行排序,然后使用
arrayInd
获取索引

d<-matrix(1:4, nrow=2)
arrayInd(order(d, decreasing=T), .dim=dim(d))

#      [,1] [,2]
# [1,]    2    2
# [2,]    1    2
# [3,]    2    1
# [4,]    1    1
d您可以使用
order()
对单元格进行排序,然后使用
arrayInd
获取索引

d<-matrix(1:4, nrow=2)
arrayInd(order(d, decreasing=T), .dim=dim(d))

#      [,1] [,2]
# [1,]    2    2
# [2,]    1    2
# [3,]    2    1
# [4,]    1    1
d您可以使用
order()
对单元格进行排序,然后使用
arrayInd
获取索引

d<-matrix(1:4, nrow=2)
arrayInd(order(d, decreasing=T), .dim=dim(d))

#      [,1] [,2]
# [1,]    2    2
# [2,]    1    2
# [3,]    2    1
# [4,]    1    1

dsee
row(d)
col(d)
order(d)
row(d)
col(d)
order(d)
row(d)
order(d)
row(d)
col。这就是我需要的。谢谢,太好了。这就是我需要的。谢谢,太好了。这就是我需要的。谢谢,太好了。这就是我需要的。非常感谢。