sortlist | R Documentation |
This function sorts the entries of a structured list in alphabetical order, including all nested sublists recursively, making it easier to navigate nested list structures and compare different lists. Unnammed items are listed last. Attributes of the original list are preserved.
sortlist(lst, recursive = TRUE, convert.data.frames = FALSE)
lst |
list to be sorted. |
recursive |
logical flag indicating whether to apply sorting recursively to all sublists.
Defaults to |
convert.data.frames |
logical flag. If |
Structured list with alphabetically sorted entries. If recursive = TRUE
, all sublists
are also sorted alphabetically. If the list contains unnamed elements, they are left unsorted.
# Create a nested list
my_list = list(
b = list(d = 4, a = 2),
empty = list(),
'unnamed',
a = 1,
f = list(b = 3, a = list(d = seq(5), 'unnamed', c = 2))
)
# Sort the list recursively
sorted_list_recursive = sortlist(my_list)
print(sorted_list_recursive)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.