You need to find the rank of each line in 20,000 lines, apply the function for too long

Please help with the following:

# create sequence of numbers a<-matrix(0:16384,1,16385) # fill matrix with this same sequence across 20,000 rows b<-matrix(a,20000,ncol(a),byrow=T) # find rank of every element, by row c<-t(apply(b,1, function(x) rank(x, ties.method="first"))) 

This is just a sample, b will have a random sequence.

Here is an example output: If b had this (now 2 rows of 3 columns):

 1 5 10 2 1 6 

I want this to be in my output:

 1 2 3 2 1 3 

It takes a very long time to process. Please, please help.

Thanks.

+5
source share

Source: https://habr.com/ru/post/1240469/


All Articles