[R] Reshape problem

arun smartpink111 at yahoo.com
Tue Oct 1 05:52:38 CEST 2013


Hi,
May be this helps.
dat1<- structure(list(trialnumber = 1:9, Control = c(0L, 1L, 0L, 0L, 
1L, 0L, 1L, 0L, 0L), HC = c(0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L
), LC = c(1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L), pleasantness = c(3L, 
3L, 2L, 2L, 3L, 4L, 3L, 3L, 2L)), .Names = c("trialnumber", "Control", 
"HC", "LC", "pleasantness"), class = "data.frame", row.names = c(NA, 
-9L))

library(reshape2)

res<- melt(dat1,id.vars=c("trialnumber","pleasantness"))
colnames(res)[3]<- "type"

A.K.


I have an experiment where people get to see a picture which is a 
control, HC or LC picture. They then have to rate its pleasantness. 

I tried to change the data so that I would get one column (for example "type" with 3 groups) instead of the 3 separate columns. 

Can anyone help me out? 
Thanks 

trialnumber	   Control	HC	LC	pleasantness 
        1	   0            0	1	3 
        2	   1	        0	0	3 
        3	   0           1	0	2 
        4	   0           1	0	2 
        5	   1	        0	0	3 
        6	   0	        0	1	4 
        7	   1	        0	0	3 
        8	   0	        0	1	3 
        9	   0	        1	0	2



More information about the R-help mailing list