Consider a list l like:
l<-list(a=24,b=12,c=30,d=1)
how to get the sorted version on values of such list, preserving names?
In result list the order of elements should be then: d,b,a and c corresponding to the sequence 1,12,24,30.
You can use order. Assuming that the length of each list element is 1 as showed in the example
l[order(unlist(l))]
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