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

Time:05-05

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.

CodePudding user response:

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

list[order(as.numeric(names(list)))]
  •  Tags:  
  • r
  • Related