Sort data frame while retaining original row id and size

What I want to do is very simple. I would like to sort this data frame df:

    Signal
1   18
2   0.043
3   549
4   9998
5   2.342

on signal to get this:

    Signal
4   9998
3   549
1   18
5   2.342
2   0.043

It is important that the original row identifiers are preserved.

I tried sort(df$Signal)and df[sort(df$Signal),]but he gives me a list.

+4
source share
1 answer

Since dfthis is a function in packet statistics, I will call your data frame d.

order , drop=FALSE [, ( ). , .

d[order(d$Signal, decreasing=TRUE),, drop=FALSE]
    Signal
4 9998.000
3  549.000
1   18.000
5    2.342
2    0.043
+6

Source: https://habr.com/ru/post/1532236/


All Articles