I have two samples x and y and I am trying to compare them with a rank sum test. For the test statistics, I am trying to get sum of the ranks of the first sample with the following.
x <- c(1,2,3,4)
y <- c(2,4,5,7)
rank(sort(c(x,y)))
[1] 1.0 2.5 2.5 4.0 5.5 5.5 7.0 8.0
However, I don't know how to draw the ranks of the values of the first sample from that. Here's what I've tried
rank(sort(c(x,y)))[x]
[1] 1.0 2.5 2.5 4.0
but it returns the wrong answer, the right should be
1.0 2.5 4.0 5.5