OECD2012  GDP2012 GDP2012born  countrynew countrybornText permile
1        1 56149.67    50632.44 Switzerland   United States       3
2        1 56149.67    45948.54 Switzerland     Netherlands       2
3        1 56149.67    44829.27 Switzerland         Ireland       1
4        1 56149.67    44551.62 Switzerland         Austria       9
5        1 56149.67    44336.81 Switzerland         Denmark       3
6        1 56149.67    43355.81 Switzerland          Sweden       1
Hi my data looks like this and I need to make it a matrix. So I run the following:
df2 <- df %>% spread(key = countrybornText, value = permile)
My problem is that I want the columns to be ordered by GDP2012born and they show up in alphabetical order when I transpose. Any idea how to keep the order I had in the column countrybornText?
df <- structure(list(OECD2012 = c(1, 1, 1, 1, 1, 1), GDP2012 = c(56149.67, 
      56149.67, 56149.67, 56149.67, 56149.67, 56149.67), GDP2012born = c(50632.44, 
      45948.54, 44829.27, 44551.62, 44336.81, 43355.81), countrynew = structure(c(1L, 
      1L, 1L, 1L, 1L, 1L), .Label = "Switzerland", class = "factor"), 
      countrybornText = structure(c(6L, 4L, 3L, 1L, 2L, 5L), .Label = c("Austria", 
      "Denmark", "Ireland", "Netherlands", "Sweden", "United States"), 
      class = "factor"), permile = c(3, 2, 1, 9, 3, 1)), class = "data.frame", 
      row.names = c(NA, -6L))
 
    