如何在R中对两个向量进行排序?

use*_*363 -2 r

我有两个向量:

vector1<- c(0.01,0.02,0.04,0.5,0.9,0.002,0.07,0.008)
 vector2<- c(1,0,0,1,0,0,0,0)
Run Code Online (Sandbox Code Playgroud)

vector2vector 1显示特定集合中每个元素的成员资格。我想排序vecotor1,但vector 2也应该排序vector 1。我怎样才能在 R 中实现它?

预期输出:

sort(vector1, decreasing=T)
[1] 0.900 0.500 0.070 0.040 0.020 0.010 0.008 0.002

>sorted_vector2:
 [1] 0 1 0 0 0 1 0 0
Run Code Online (Sandbox Code Playgroud)

Mat*_*erg 5

使用order,返回 所使用的排列sort:

vector2[order(vector1, decreasing=TRUE)]
[1] 0 1 0 0 0 1 0 0
Run Code Online (Sandbox Code Playgroud)