[R] Reshape a data set

dadrivr dadrivr at gmail.com
Sun Dec 13 21:04:17 CET 2009


I am trying to reshape a data set.  Could someone please help me with the
reshape, cast, and melt functions?  I am new to R and I have tried reading
up on how to use the reshape package, but I am very confused.  Here is an
example of what I am trying to do:
     subject coder score time
[1,]       1     1    20    5
[2,]       1     2    30    4
[3,]       2     3    10   10
[4,]       2     2     5   12
[5,]       3     2    15   NA
[6,]       3     1    NA   13

Reshape to:
     subject coder.1  score.1 time.1 coder.2 score.2 time.2
[1,]  1           1         20       5        2          30      4
[2,]  2           3         10      10       2           5      12
[3,]  3           2         15      NA       1          NA     13

Here is the code to setup the original data set that I need to reshape:
subject <- c(1,1,2,2,3,3)
coder <- c(1,2,3,2,2,1)
score <- c(20,30,10,5,15,NA)
time <- c(5,4,10,12,NA,13)
mydata <- cbind(subject,coder,score,time)

Here is where I'm not sure:
library(reshape)
mydata_melt <- melt(mydata, id="subject", na.rm=TRUE) 
mydata_cast <- cast(mydata, ???

Any help would be greatly appreciated.  Thanks so much!
-Isaac
-- 
View this message in context: http://n4.nabble.com/Reshape-a-data-set-tp963104p963104.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list