Sort matrix according to first column in R

后端 未结 5 1378
抹茶落季
抹茶落季 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条回答
  •  眼角桃花
    2020-12-07 18:15

    The accepted answer works like a charm unless you're applying it to a vector. Since a vector is non-recursive, you'll get an error like this

    $ operator is invalid for atomic vectors
    

    You can use [ in that case

    foo[order(foo["V1"]),]
    

提交回复
热议问题