Rounding step in base::rank()? I have been trying to compare rankings between 2 lists. The list components are random effects from a mixed model, so they are shrunken towards zero and mean-centered as well. 
R's base function:
cor(x,y,method = "spearman") 

relies on another base function, rank(), which appears to first convert everything to an integer, the mathematically equivalent of rounding down by dropping everything after a decimal point. 
# example where ranks and order are identical:

x0<-as.numeric(1:500)
order(x0)
rank(x0)

sum(abs(order(x0) - rank(x0)))

# example where ranks and order differ

set.seed(300)
x1<-rnorm(500,1,50)

order(x1)
rank(x1)
order(as.integer(x1))

sum(abs(order(x1) - rank(x1)))

Converting to an integer does flatten out the data by creating more duplicated data points:
>length(unique(as.character(as.integer(x1))))
[1] 186
> length(unique(as.character(x1)))
[1] 500

Is there any statistical justification for this rounding step? As is, it looks like an unfortunate error to use rank(). Unless I'm missing something (which is what I what I would like to find out from the cross validated folks), by rounding the values, the spearman correlations are overestimated by creating more ties than what actually occurs in the data. 
 A: Repeating some of the points in the comments:


*

*rank() does not always take integer values

*order() always takes integer values though it is not a ranking of the original values but the original location of the sorted values 

*cor(x, y, "method = "spearman") uses rank()
Try the illustration illustration: rank(x) and order(x) are different both in terms of integers and values while rank(y) and order(y) misleadingly look the same.  Consider where 2 appears:


*

*With rank(x), the fifth value is 2 because x[5] is the second lowest value of x;  

*with order(x), the third value is 2 because x[2] is the third lowest of x.  

*With rank(y), the first value is 2 because y[2] is the lowest value of y; 

*with order(y), the first value is  2 because y[1] is the second lowest of y.


You can also see that cor(x, y, method = "spearman") is based on rank() rather than order() 
> x <- c(20,40,50,50,30)
> y <- c(70,60,80,90,110)
> rank(x)
[1] 1.0 3.0 4.5 4.5 2.0
> order(x)
[1] 1 5 2 3 4
> rank(y)
[1] 2 1 3 4 5
> order(y)
[1] 2 1 3 4 5
> cor(x, y, method = "spearman") 
[1] 0.1538968
> cor(rank(x),  rank(y),  method="pearson")
[1] 0.1538968
> cor(order(x), order(y), method="pearson")
[1] 0

