
Hello, I would like to order a matrix by a specific column. For instance:

 

> test
      [,1] [,2] [,3]
 [1,]    1  100   21
 [2,]    2    3   22
 [3,]    3  100   23
 [4,]    4   60   24
 [5,]    5   55   25
 [6,]    6   45   26
 [7,]    7   75   27
 [8,]    8   12   28
 [9,]    9   10   29
[10,]   10   22   30
>

 test[order(test[,2]),]
      [,1] [,2] [,3]
 [1,]    2    3   22
 [2,]    9   10   29
 [3,]    8   12   28
 [4,]   10   22   30
 [5,]    6   45   26
 [6,]    5   55   25
 [7,]    4   60   24
 [8,]    7   75   27
 [9,]    1  100   21
[10,]    3  100   23


This works well and good in the above example matrix.  However in the matrix that I actually want to sort (derived from a function that I wrote) I get something like this:

 

> test[order(as.numeric(test[,2])),]     ### First column is row.names


         f con f.1 cov f.2 minimum f.3 maximum f.4   cl
asahi    * 100   *   1   *     0.1   *       2   * test
castet   * 100   *   2   *     0.1   *       5   * test
clado    * 100   *   1   *     0.7   *       2   * test
aulac    *  33   *   0   *     0.1   *     0.1   * test
buell    *  33   *   0   *     0.1   *     0.1   * test
camlas   *  33   *   0   *     0.1   *     0.1   * test
carbig   *  33   *   1   *       1   *       1   * test
poaarc   *  67   *   0   *     0.1   *     0.1   * test
polviv   *  67   *   0   *     0.1   *     0.1   * test


 

where R interprets 100 to be the lowest value and orders increasing from there.  

 

> is.numeric(test[,2])
[1] FALSE
> is.double(test[,2])
[1] FALSE
> is.integer(test[,2])
[1] FALSE
> is.real(test[,2])
[1] FALSE


 

My questions are:  Why is this happening? and How do I fix  it? 

 

Thanks in advance!

 

                              Aaron Wells

_________________________________________________________________


cns!503D1D86EBB2B53C!2285.entry?ocid=TXT_TAGLM_WL_UGC_Contacts_032009
	[[alternative HTML version deleted]]


