我可以轻松地订购这样的数据框:
df<-data.frame(a=c(1,2,5,7,2),b=(1:5))
# indexing by column name, works
df2<-df[with(df,order(a)),]
但是如何通过使用列号进行索引来实现相同的目标?
# indexing with column number, attemps failed
df2<-df[with(df,order(colnames(df[1]))),]
df2<-df[with(df,order(deparse(colnames(df[1])))),]
df2<-df[with(df,order(paste(colnames(df[1])))),]
df2<-df[with(df,order(paste(deparse(colnames(df[1]))))),]