# simple design: accuracy measured at two time points for 4 participants
wide <- data.frame(
id = 1:4,
accuracy_t1 = c(.15, .50, .78, .55),
accuracy_t2 = c(.55, .32, .99, .60)
)
wideToLong(wide, "time")
# complex design: two measures (MRT, PC), two conditions, two days
wide2 <- data.frame(
id = 1:4,
gender = factor(c("male", "male", "female", "female")),
MRT_cond1_day1 = c(415, 500, 478, 550),
MRT_cond2_day1 = c(455, 532, 499, 602),
MRT_cond1_day2 = c(400, 490, 468, 502),
MRT_cond2_day2 = c(450, 518, 474, 588),
PC_cond1_day1 = c(79, 83, 91, 75),
PC_cond2_day1 = c(82, 86, 90, 78),
PC_cond1_day2 = c(88, 92, 98, 89),
PC_cond2_day2 = c(93, 97, 100, 95)
)
# default: condition and day become separate columns
wideToLong(wide2, within = c("condition", "day"))
# alternative: keep condition and day as one combined column
wideToLong(wide2, split = FALSE)
Run the code above in your browser using DataLab