I need to use R to print dataset of a dataframe so that columns are in alphabetical order. It sounds sorting column name is required. I tried sort (data.frame$) but it didn't work. Can anybody help me?
You can use the code below
df[order(names(df))]
or
df[sort(names(df))]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.