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
By Signal
, in order to obtain this:
Signal
4 9998
3 549
1 18
5 2.342
2 0.043
It's important that the original row IDs are conserved.
I tried sort(df$Signal)
and df[sort(df$Signal),]
but it gives me a list.
As df
is a function in package stats, I will call your data frame d
.
order
does indeed do the job, but you need to supply drop=FALSE
to [
to prevent getting a vector (dropping a dimension). The dimension is dropped by default when possible, and here it is possible.
d[order(d$Signal, decreasing=TRUE),, drop=FALSE]
Signal
4 9998.000
3 549.000
1 18.000
5 2.342
2 0.043
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With