[R] How to rank vectors based on their elements?

Petr Savicky savicky at cs.cas.cz
Sun Apr 15 11:25:20 CEST 2012

On Sat, Apr 14, 2012 at 07:10:48PM -0700, Manish Gupta wrote:
> Hi,
> I am working on ranking algo? I have data which is in the form of vectors
> (feature) for each class and i need to rank them based on feature vector.
> class1<-c(1,3,4,-2,0)
> class2<-c(2,0,0,-3,0)
> class3<-c(2,3,1,4,5)
> class4<-c(-4,-5,1,0,0)
> I need to rank class1, class2, class3, class4 & class5. How can i implement
> it?


I am not sure, whether i understand, what you mean. How many examples
of each class do you have? Do you have one example for each class
consisting of 5 features or you have 5 examples for each class,
where each example is represented by a single number?

The usual format for a classification task is a matrix or data frame
with one column for each feature and one column for the class. The first
interpretation would be represented by the matrix

   1   3   4  -2   0  class1 
   2   0   0  -3   0  class2 
   2   3   1   4   5  class3 
  -4  -5   1   0   0  class4 

and the other interpretation would be represented by

   1  class1
   3  class1
   4  class1
  -2  class1
   0  class1
   2  class2
   0  class2
   0  class2
  -3  class2
   0  class2
   2  class3
   3  class3
   1  class3
   4  class3
   5  class3
  -4  class4
  -5  class4
   1  class4
   0  class4
   0  class4

Is some of this meaningful in your application?

What do you mean by ranking? Do you mean to estimate to which class
belongs a new example not contained in the data above? Another
understanding may be that you want to order the four classes by
some type of average of the numbers assigned to each of them.

Petr Savicky.

More information about the R-help mailing list