如何在r中对表中的列进行排序

时间:2013-07-03 16:06:16

标签: r sorting merge

我尝试合并两个表,但结果是这样的,

 subj gamble_gamble n_gambles expected_value
   1            19        32            1.7
  10             3         4            1.5
 100             3         4            1.5
 101             6        32            1.4
 102             3         4            1.5
 103            19        32            1.7

subj列未按常规方式排序(例如1,2,3,4,5,6)。我尝试使用此命令对subj列进行排序:

newdata <- table3[order(subj),]

但它不起作用。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:2)

使用此:

newdata <- table3[order(as.numeric(as.character(table3$subj))),]

即使subjfactor(不仅仅是character),此功能仍然有用。