#In a wide data set, we have five variables we want to put in a long format
#ID and the z-transformed pre- and posttest of two scales (Memory and Life Satisfaction)
#The first two lines below select the variables of interest, and melt creates a four-line-per-person
#long data set. Signifying "id.vars=ID" means that participant ID will appear on each of a person's
#four rows.
col_plot3 = c("ZLifeSat","ZLifeSat2_correct","ZMemory", "ZMemory2_correct")
dlong3 <- melt(Wk07a[,c("ID", col_plot3)], id.vars="ID") #Ignore warning
#Each row has a variable called "variable", which is the name of the original column it was in
#Each row as a variable called "value", which is the score the participant had in that original column
#We would like to add two coding vectors. One(Prepost) will indicate what occasion the data are from (pre- or
#posttest). The other (Task) will indicate whether the value is for Memory or Life Satisfaction.

dlong3$Prepost[dlong3$variable == "ZLifeSat" | dlong3$variable == "ZMemory" ] <- "0.Pretest"
dlong3$Prepost[dlong3$variable == "ZLifeSat2_correct" | dlong3$variable == "ZMemory2_correct" ] <- "1.Posttest"
dlong3$Task[dlong3$variable == "ZLifeSat" | dlong3$variable == "ZLifeSat2_correct" ] <- "ZLifeSat"
dlong3$Task[dlong3$variable == "ZMemory" | dlong3$variable == "ZMemory2_correct" ] <- "ZMemory"