I have made a matrix where each element in the matrix is a vector of two numbers. Now I want to rank all the vectors inside, so I get the rank of the vectors as the new vector elements of the matrix.
Here is an example of the code:
listwvectors <- vector("list")
t=1
for (i in 1:3) {
for (j in 1:5) {
listwvectors[[t]] <- c(i,j)
t=t+1
}
}
print(listwvectors)
testmatrix <- matrix(data=listwvectors, nrow=5, ncol=3)
print(testmatrix)
rank(testmatrix[1,1])
The last part ("rank(testmatrix[1,1])") just give 1. Why is that? I want it to print the ranked vector. So in fact, I want to make a new matrix that has the same mode as the testmatrix but the vectors inside is the ranked vectors of the testmatrix.
Hope you understand what I am trying to ask. Thanks in advance!:)