I have a named list:
The_list
$df1
col1 col2
1 M P
2 N Q
3 O R
$df2
col1 col2
1 G J
2 H K
3 I L
$df3
col1 col2
1 A D
2 B E
3 C F
How could I do a custom (i.e. not alphabetical) sort of the list by names that is stored in a vector:
order <- c("df2", "df3", "df1")
and then get :
The_list
$df2
col1 col2
1 G J
2 H K
3 I L
$df3
col1 col2
1 A D
2 B E
3 C F
$df1
col1 col2
1 M P
2 N Q
3 O R
So far I tried:
The_list[order(c("df2", "df3", "df1"))]
CodePudding user response:
The_list[c("df2","df3","df1")]