# How to sort a list that contains single sub-elements in decreasing order in R?

Just like a list can have multiple elements, the elements of the list can have multiple sub-elements and the size of those elements may vary as well hence a list with single sub-elements is also possible. If we have such type of list then we can sort that list in decreasing order by using order function but we also need to unlist those elements.

## Example

Consider the below list −

Live Demo

x1<-500
x2<-245
x3<-128
x4<-325
x5<-854
x6<-329
x7<-742
x8<-214
x9<-374
x10<-524
List1<-list(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10)
List1

## Output

[]
 500
[]
 245
[]
 128
[]
 325
[]
 854
[]
 329
[]
 742
[]
 214
[]
 374
[]
 524

Decreasing the elements of List1 −

## Example

List1[order(unlist(List1),decreasing=TRUE)]

## Output

[]
 854
[]
 742
[]
 524
[]
 500
[]
 374
[]
 329
[]
 325
[]
 245
[]
 214
[]
 128

Let’s have a look at another example −

## Example

Live Demo

y1<-241
y2<-215
y3<-421
y4<-295
y5<-371
y6<-501
y7<-652
y8<-719
y9<-814
y10<-110
List2<-list(y1,y2,y3,y4,y5,y6,y7,y8,y9,y10)
List2

## Output

[]
 241
[]
 215
[]
 421
[]
 295
[]
 371
[]
 501
[]
 652
[]
 719
[]
 814
[]
 110

Decreasing the elements of List2 −

## Example

List2[order(unlist(List2),decreasing=TRUE)]

## Output

[]
 814
[]
 719
[]
 652
[]
 501
[]
 421
[]
 371
[]
 295
[]
 241
[]
 215
[]
 110