如何按列标题对数据帧进行排序,列标题是文本和数字的混合

时间:2017-07-14 08:18:42

标签: r sorting

我的数据框如下所示

   GR1-text GR11-text GR12-text GR2-text
A    1          1       0          0
B    1          0       1          1

我想将数据框排序为:

   GR1-text  GR2-text  GR11-text  GR12-test
A   1         0         1           0
B   1         1         0           1

我尝试了following没有效果

test <- df[ , order(names(df))]

我也发现了这个custom function,但我看不到让它发挥作用。

1 个答案:

答案 0 :(得分:0)

尝试使用order(readr::parse_number(names(df)))