sorting - Sort list by values preserving names in R -
consider list l like:
l<-list(a=24,b=12,c=30,d=1) how sorted version on values of such list, preserving names?
in result list order of elements should then: d,b,a , c corresponding sequence 1,12,24,30.
you can use order. assuming length of each list element 1 showed in example
l[order(unlist(l))]
Comments
Post a Comment