longToWide( data, formula, sep="_")sep. In the example above where the reshaping formula was accuracy ~ time, if the default separator of sep="_" was used, and the levels of the time variable are t1, t2 and t3, then the output would include the variables accuracy_t1, accuracy_t2 and accuracy_t3. In the second example listed above, where the reshaping formula was rt + accuracy ~ days + sessions, the output variables would refer to levels of both within-subjects variables. For instance, rt_day1_session1, and accuracy_day2_session1 might be the names of two of the variables in the wide form data frame.
longToWide function is the companion function to wideToLong. The data argument is a "long form" data frame, in which each row corresponds to a single observation. The output is a "wide form" data frame, in which each row corresponds to a single experimental unit (e.g., a single subject). The reshaping formula should list all of the measure variables on the left hand side, and all of the within-subject variables on the right hand side. All other variables are assumed to be between-subject variables. For example, if the accuracy of a participant's performance is measured at multiple time points, then the formula would be accuracy ~ time.
Multiple variables are supported on both sides of the formula. For example, suppose we measured the response time rt and accuracy of participants, across three separate days, and across three separate sessions within each day. In this case the formula would be rt + accuracy ~ days + sessions.
wideToLong, reshape, stack, cast and melt (in the long <- data.frame( id = c(1,2,3,1,2,3,1,2,3),
time = c("t1","t1","t1","t2","t2","t2","t3","t3","t3"),
accuracy = c(.50,.03,.72,.94,.63,.49,.78,.71,.16) )
longToWide( long, accuracy~time)Run the code above in your browser using DataLab