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
Привет, мои данные выглядят так, и мне нужно сделать их матричными. Поэтому я запускаю следующее:
df2 <- df %>% spread(key = countrybornText, value = permile)
Моя проблема в том, что я хочу, чтобы столбцы упорядочивались GDP2012born, и они отображаются в алфавитном порядке, когда я переставляю. Любая идея, как сохранить порядок, который я имел в столбце 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))