If I have a list like so:
test_100 = data.frame(rnorm(10),rnorm(10))
test_40 = data.frame(rnorm(10),rnorm(10))
test_20 = data.frame(rnorm(10),rnorm(10))
test_50 = data.frame(rnorm(10),rnorm(10))
mylist = list(test_100,test_40,test_50,test_20)
names(mylist)=c('test_100','test_40','test_20','test_50')
and I wanted to order the items from lowest to highest (i.e test_20
, test_40
,test_50
,test_100
), how would I do this?
The purpose of this is because the data.frames above will be passed through grid.arrange and I want the plots to be in order from lowest to highest. I'm trying to make the code as generic as possible in case there are more then 4 data.frames in that list.
I could try something like:
as.numeric(gsub('.*?(\\d+)','\\1',names(mylist)))
to extrace the number but how would I then sort based on this?