How do I order my data based on the names of my list?

Viewed 20

My list looks something like this: enter image description here

I have converted the string values (such as rs267) to numbers but when I try:

lapply(list, function(x) sort(x))

My data ends up being sorted by the values of the list. But I want it to be sorted by the name values, since these are numeric.

1 Answers

Convert the names (character) to numeric, apply order and use that index for ordering the list

list[order(as.numeric(names(list)))]
Related