1

被験者間で繰り返し評価を行う大規模なデータセットがあります。どうやって行くのですか:

subj, assessment, test1, test2  
A,    1,          10,    20  
A,    2,          12,    13  
A,    3,          11,    12  
B,    1,          14,    14  
B,    2,          13,    12

に:

subj, test1_1, test1_2, test1_3  
A,    10,      12,      11  
B,    14,      13  

ありがとう、

ジョン

4

2 に答える 2

2

reshape 関数 (統計内) は、これをかなり簡単に行います。

reshape(data, timevar='assessment', idvar='subj', dir='wide')

または、test1 の結果を取得するには:

reshape(subset(data, select=-test2), timevar='assessment', idvar='subj', dir='wide')
于 2010-09-20T16:38:40.270 に答える
2

you can easily accomplish this using the excellent reshape/ reshape2 package by hadley. here is the code to take you to what you need

library(reshape); 
df = melt(df, id = c('subj', 'assessment'));
df = cast(df, subj ~ variable + assessment);

let me know if this works for you.

于 2010-09-20T16:32:27.533 に答える