2017-05-30 10 views
0

私はtidyrとdplyrの使用を開始しています。私は、次のデータフレームを有する:データの再フォーマット

      email Assignment Stage Grade 
1      [email protected] course final 86.28 
2      [email protected] course first 68.87 
3      [email protected] course resub 38.06 
4      [email protected] course final 77.41 
... 

Iは、段階(第1、RESUB又は最終)の値に基づくようにこれを再構築したいIステージの値に対応する一つグレードカラムからの3つの列を作成します

      email Assignment first resub final 
1      [email protected] course 100.0 100.0 100.0 
2      [email protected] course 100.0 100.0 100.0 
3      [email protected] course 100.0 100.0 100.0 
4      [email protected] course 100.0 100.0 100.0 

(データは明らかにあるため、カット/ペーストのマッチングされていません。)

私は混乱しています、私は別の()関数が必要ですが、どのようにしますか?ありがとう!

答えて

1

tidyrのspread()関数は、必要な結果を得るはずです。

email <- c("[email protected]","[email protected]","[email protected]","[email protected]") 
Assignment <- rep("course",4) 
Stage <- c("final","first","resub","final") 
Grade <- c(86.28,68.87,38.06,77.41) 

df <- data.frame(email,Assignment,Stage,Grade,stringsAsFactors = FALSE) 

df <- df %>% 
     spread(Stage, Grade) 
関連する問題