【发布时间】:2018-10-17 20:18:00
【问题描述】:
我不知道在这个问题中 X 或 Y 向量是如何相互关联的。答案是单个向量这一事实最让我困惑。
我尝试做负排名(即排名(-s)),然后尝试
rev(rank(X)) 和 rev(rank(Y)) 我得到不正确的排名返回。这是我的代码:
x <- c(-1, 0, 1, 2, -3) #vector x
y <- c(1, 3, 2, 5, 8) # Vector y
S <- x[order(match(x,y))] #orders and matches x with y
R <- rank(-S) #ranks S in element number order
print(R) #I want R = (5 2 1 3 4)
相反,我得到[2 1 4 3 5]
使用其他代码:
never <- rev(rank(-x)) #takes the reverse rank of x
bird <- rev(rank(y)) #takes the reverse rank of y
kid <- x[order(match(never, bird))] #orders the match of the reverse ranks
tr <- rank(kid) #ranks the match of the reverse ranks
print(tr)
我收到[2 1 3 4 5]。
【问题讨论】:
-
Pr0P5 4 dE 0utr1Ght bRAzenNes5
-
好吧,我们知道你擅长一件事。
标签: r