重新排序数据框的列

时间:2018-04-05 12:46:20

标签: r dataframe output

假设以下数据框df

  k    final01    final12     final11     final10     final13     final14    final15
1 0 0.01132197 0.01242985 0.003420944 0.003734922 0.004676629 0.003233194 0.02645520
2 1 0.02945764 0.02462278 0.008050575 0.008931167 0.006695612 0.004657732 0.03373639
3 2 0.02802845 0.02486389 0.006674203 0.006913728 0.006871522 0.004799810 0.02929527
4 3 0.02753059 0.02500377 0.006830818 0.006857118 0.006937120 0.004930983 0.02933087
5 4 0.02739441 0.02474920 0.006954684 0.006649320 0.006512953 0.004712823 0.02819380
6 5 0.02782208 0.02465878          NA          NA          NA          NA         NA

此处为dput(df)

structure(list(k = 0:5, final01 = c(0.0113219652566949, 0.0294576400488878, 
0.0280284464532738, 0.0275305922885969, 0.0273944087059707,0.0278220846696326
), final10 = c(0.0124298469345964, 0.024622784463692, 0.0248638940062316, 
0.025003765032319, 0.0247492039902097, 0.0246587782824302), final11 = c(0.00342094396763939, 
0.00805057453957241, 0.00667420265709246, 0.00683081837187657, 
0.00695468361107997, NA), final12 = c(0.00373492219945338, 0.00893116747327287, 
0.00691372841938441, 0.00685711798770184, 0.00664932025914572, 
NA), final13 = c(0.00467662856293965, 0.00669561244661012, 0.00687152189408537, 
0.00693712042565242, 0.00651295285883445, NA), final14 = c(0.00323319390635929, 
0.00465773181030785, 0.00479980993663797, 0.00493098278746824, 
0.00471282267245847, NA), final15 = c(0.0264552040924062, 0.0337363880196297, 
0.0292952726979338, 0.0293308732480174, 0.0281937993522965, NA
)), .Names = c("k", "final01", "final10", "final11", "final12", 
"final13", "final14", "final15"), class = "data.frame", row.names = c(NA, 
6L))

我想像我这样重新排序我的数据框:

   k final01 final10 final11 final12 final13 final14 final15
1  0
2  1
3  2
4  3
5  4
6  5

这只是一个简短的例子。如果有帮助:我的数据框包含final01-final20

中的列

0 个答案:

没有答案