Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - Change the order of elements in a list

Tags:

list

r

I need to change the order of elements in a list. I don't find a patent response in others questions about sort or order a list.

Here is a simple example.

Freedom <- c(1, 2, 3, 2, 1, 2)
Equality <- c(2, 3, 1, 1, 2, 1)
TypeCountry <- c("South", "East", "East", "North", "South", "West")

Example <- list(Freedom, Equality, TypeCountry)
names(Example) <- c("Freedom", "Equality", "TypeCountry")

The list has the order Freedom, Equality then TypeCountry and I want to be able to change the order of the elements (for example Equality, Freedom then TypeCountry).

like image 340
Kumpelka Avatar asked Nov 15 '16 16:11

Kumpelka


1 Answers

Just do this:

Ex <- Example[c("TypeCountry","Freedom", "Equality")]

You specify the order you want.

like image 126
Diego Rodrigues Avatar answered Nov 11 '22 12:11

Diego Rodrigues