我有一个看起来像
的数据集A T Value into T A Value
1 1 32 1 1 32
1 2 33 1 2 55
1 3 34 1 3 96
2 1 55 2 1 33
2 2 56 2 2 56
2 3 57 2 3 97
3 1 96 3 1 34
3 2 97 3 2 57
3 3 98 3 3 98
我希望使用reshape(在R中)重新整形左边的这个对象,以便T索引在第一列中,A索引在第二列中以获取右边的对象。我没有熔化或演员功能。
答案 0 :(得分:3)
让df
成为您的data.frame
。
df <- df[order(df$T, df$A), c("T", "A", "Value")]
这可以通过下次谷歌搜索轻松找到。
答案 1 :(得分:3)
看起来您只想对行进行排序并移动列。如果这是您的样本输入
tt<-read.table(text="A T Value
1 1 32
1 2 33
1 3 34
2 1 55
2 2 56
2 3 57
3 1 96
3 2 97
3 3 98", header=T)
你可以做到
tt[order(tt$T, tt$A), c("T","A","Value")]