I need to order my df in R alphabetically with a lot o columns...
library(dplyr)
df <- data.frame(
colname = c(
"a",
"nb",
"s",
"b",
"c",
"sd",
"sdsd",
"sdsdtr",
"y",
"sasa",
"de",
"fe",
"rwew",
"dsd",
"ewew"
),
value = seq_along(1:15)
)
df
colname value
1 a 1
2 nb 2
3 s 3
4 b 4
5 c 5
6 sd 6
7 sdsd 7
8 sdsdtr 8
9 y 9
10 sasa 10
11 de 11
12 fe 12
13 rwew 13
14 dsd 14
15 ewew 15
Suppose I have much more than just 15 columns, as demonstrated here in the small example, how could I use some R function to sort my df columns by column names alphabetically?