knitr::opts_chunk$set(echo = TRUE)
 wide_data <- data.frame(participant = 1:10, 
                         Morning_A_Noisy = c(61, 100, 70, 100, 93, 70, 85, 51, 70, 50),
                         Morning_B_Noisy = c(77, 68, 56, 84, 62, 72, 86, 78, 85, 81),
                         Afternoon_A_Noisy = c(97, 92, 89, 59, 83, 72, 69, 69, 93, 96),
                         Afternoon_B_Noisy = c(97, 57, 78, 85, 53, 99, 67, 59, 87, 90),
                         Evening_A_Noisy = c(89, 55, 98, 73, 80, 53, 54, 96, 78, 71), 
                         Evening_B_Noisy = c(94, 85, 73, 74, 78, 70, 90, 90, 64, 83),
                         Morning_A_Quiet = c(87, 96, 86, 50, 98, 85, 93, 72, 100, 76),
                         Morning_B_Quiet = c(87, 88, 86, 62, 69, 60, 53, 61, 98, 64),
                         Afternoon_A_Quiet = c(65,91,99,89,100,81,63,97,68,50),
                         Afternoon_B_Quiet = c(53,56,92,61,73,72,61,82,82,75),
                         Evening_A_Quiet = c(79,90,67,85,69,65,74,57,55,56),
                         Evening_B_Quiet = c(51,53,96,67,56,60,59,83,58,72))

knitr::kable(wide_data)

#note - changed headers in excel to match time of day & condition
library(tidyr)

pivot_longer(data = wide_data, 
             cols = !participant,
             names_to = "time_of_day",
             values_to = "counts")

I didn't use the solution video but did copy & modify code from the assignment site. I tried to write it myself first but used the pivot_longer code to finally get the data in long form.



celiaflorea/statslab2022 documentation built on Aug. 31, 2022, 5:29 p.m.