【R】【unimplemented type ‘list’ in ‘orderVector1’】

I. Problem description
When using the R language, you want to use the order function for a matrix to sort by a column, and the result is an error

> print(rep_motion)
       [,1]        [,2]         [,3]     
  [1,] NaN         NaN          NaN      
  [2,] 0.0434575   0.01098376   0.9512894
  [3,] 0.001588562 0.001588562  0.99722  
  [4,] 0.004219409 0            0.9978903
  [5,] 0.004721435 0.0006295247 0.9952786
  [6,] 0.008078995 0.000598444  0.9931179
  [7,] 0.01246883  0.009975062  0.9806733
  [8,] 0           0            1        
  [9,] 0.03324361  0.02113055   0.9510094
  [10,] 0.02582149  0.01563      0.9611535
  [11,] 0.006769826 0.005802708  0.9883946
  [12,] 0.001959248 0.0003918495 0.9980408
  [13,] 0.002842524 0.0005685048 0.9971575
  [14,] 0.00748183  0.001710133  0.9910218
  [15,] 0.02713675  0.01901709   0.9626068
  [16,] 0.03195067  0.009529148  0.9646861
  [17,] 0.01386159  0.01799938   0.9778628
  [18,] 0.02140673  0.1569827    0.9006116
  [19,] 0.06902854  0.01588641   0.9190215
  [20,] 0.006300257 0.003150128  0.9912957
  [21,] 0.01619586  0.006779661  0.9777778
  [22,] 0.006226313 0.00351922   0.9910666
  [23,] 0.01170929  0.005552047  0.9836333
> rep_motion[order(rep_motion[,3])]
   Error in order(rep_motion[, 3]) : unimplemented type 'list' in 'orderVector1'

Ii. Problem Solving
Check out the type of REP_motion:

> typeof(rep_motion)
  [1] "list"
> mode(rep_motion)
  [1] "list"
> class(rep_motion)
  [1] "matrix"

The reason is that when you create this matrix, you group each row together as a list, so that when you order, you are ordering the list, not the number. Numbers are sized so they can be sorted, while list is not, so it will report an error.
when your matrix changes to the following type, it will not report an error.

> typeof(evaluated)
  [1] "double"
> mode(evaluated)
  [1] "numeric"
> class(evaluated)
  [1] "matrix"

It depends on how you define it. If you still have not solved, welcome to exchange in the comments section!


Read More: