Sort matrix according to first column in R

后端 未结 5 1386
抹茶落季
抹茶落季 2020-12-07 17:50

I have a matrix with two columns of the following form:

1 349
1 393
1 392
4 459
3 49
3 32
2 94

I would like to sort this matrix in increasi

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 18:20

    Creating a data.table with key=V1 automatically does this for you. Using Stephan's data foo

    > require(data.table)
    > foo.dt <- data.table(foo, key="V1")
    > foo.dt
       V1  V2
    1:  1 349
    2:  1 393
    3:  1 392
    4:  2  94
    5:  3  49
    6:  3  32
    7:  4 459
    

提交回复
热议问题