I have an experiment with 3 within-subject factors, each with two levels, summing to eight conditions per participant. My df now has one id column, three factor columns, and one column for my dependent variable, so it looks something like (for the first 2 subjects):
Df <- data.frame(id = c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2),
factor1 = c("A", "A", "A", "A", "B", "B","B","B","A", "A", "A", "A", "B", "B","B","B"),
factor2 = c("x", "x", "y", "y", "x", "x", "y", "y","x", "x", "y", "y", "x", "x", "y", "y"),
factor3 = c(4, 8, 4, 8, 4, 8, 4, 8,4, 8, 4, 8, 4, 8, 4, 8),
dv = c(5.5, 4.1, 3.9, 2.7, NA, 9.9, 1.7, 5.2,3.0,2.8,2.2,8.0,9.9,2.6,0.1,3.0))
I want to look at things such as the difference between my dv for factor3 levels 4 and 8 for factor1 "A" and factor2 "x", and to do this for each participant. I figured that a good way to achieve this would be to first reorganize my df such that each subject is represented by one row, and each combination of factors is a column. Something like:
Df2 <- data.frame(id = c(1, 2),
Ax4 = c(5.5, 3.0),
Ax8 = c(4.1, 2.8),
Ay4 = c(3.9, 2.2),
Ay8 = c(2.7, 8.0),
Bx4 = c(NA, 9.9),
Bx8 = c(9.9, 2.6),
By4 = c(1.7, 0.1),
By8 = c(4.2, 3.0))
First of all - does this make sense? If yes - what is a simple way to perform this transformation? If not - what is an alternative way to extract differences between factor combinations per each participant?
Thanks!