

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to sort a list that contains single sub-elements in decreasing order in R?
<p>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.</p><h2>Example</h2><p>Consider the below list −</p><p><a class="demo" href="http://tpcg.io/PdEtVgLL" rel="nofollow" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate">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</pre><h2>Output</h2><pre class="result notranslate">[[1]] [1] 500 [[2]] [1] 245 [[3]] [1] 128 [[4]] [1] 325 [[5]] [1] 854 [[6]] [1] 329 [[7]] [1] 742 [[8]] [1] 214 [[9]] [1] 374 [[10]] [1] 524</pre><p>Decreasing the elements of List1 −</p><h2>Example</h2><pre class="prettyprint notranslate">List1[order(unlist(List1),decreasing=TRUE)]</pre><h2>Output</h2><pre class="result notranslate">[[1]] [1] 854 [[2]] [1] 742 [[3]] [1] 524 [[4]] [1] 500 [[5]] [1] 374 [[6]] [1] 329 [[7]] [1] 325 [[8]] [1] 245 [[9]] [1] 214 [[10]] [1] 128</pre><p>Let’s have a look at another example −</p><h2>Example</h2><p><a class="demo" href="http://tpcg.io/ujw7SaKR" rel="nofollow" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate">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</pre><h2>Output</h2><pre class="result notranslate">[[1]] [1] 241 [[2]] [1] 215 [[3]] [1] 421 [[4]] [1] 295 [[5]] [1] 371 [[6]] [1] 501 [[7]] [1] 652 [[8]] [1] 719 [[9]] [1] 814 [[10]] [1] 110</pre><p>Decreasing the elements of List2 −</p><h2>Example</h2><pre class="prettyprint notranslate">List2[order(unlist(List2),decreasing=TRUE)]</pre><h2>Output</h2><pre class="result notranslate">[[1]] [1] 814 [[2]] [1] 719 [[3]] [1] 652 [[4]] [1] 501 [[5]] [1] 421 [[6]] [1] 371 [[7]] [1] 295 [[8]] [1] 241 [[9]] [1] 215 [[10]] [1] 110</pre>
- Related Questions & Answers
- How to sort a vector in increasing order that contains numbers and characters in R?
- Decreasing order sort of alphabets in JavaScript
- Sort list elements in descending order in C#
- How to delete a list element that only contains NA in R?
- How to convert list elements into a single string in R?
- How to subset one or more sub-elements of a list in R?
- How to change the order of elements in a list in R?
- Find smallest subarray that contains all elements in same order in C++
- How to check whether the elements of a vector are arranged in an increasing order or decreasing order?
- How to replace a sub-string with the reverse of that sub-string in R?
- How to sort Java array elements in ascending order?
- Sort a List in reverse order in Java
- How to check whether a List contains the elements that match the specified conditions in C#?
- Print array elements in alternatively increasing and decreasing order in C++
- C++ Program to Sort Elements in Lexicographical Order (Dictionary Order)
Advertisements