Conversion of data into long format

Load necessary libraries

library(tidyverse)

Assume the data is read from a CSV file or created as shown below

data <- tibble::tribble(
~Participant, ~Trial, ~Condition, ~Rating1, ~Rating2, ~Rating3, ~Rating4,
1, 1, "Repetition", 2, 2, 5, 2,
2, 2, "No reptn", 3, 3, 4, 5,
3, 3, "Repetition", 4, 3, 6, 4,
4, 4, "No reptn", 6, 2, 6, 4,
5, 5, "Repetition", 5, 5, 3, 2,
6, 6, "No reptn", 2, 4, 5, 1,
7, 7, "Repetition", 4, 3, 6, 4,
8, 8, "No reptn", 3, 7, 7, 7,
9, 9, "Repetition", 1, 7, 3, 6,
10, 10, "No reptn", 4, 6, 5, 6,
11, 11, "Repetition", 4, 2, 4, 5,
12, 12, "No reptn", 2, 3, 3, 4,
13, 13, "Repetition", 7, 6, 5, 4,
14, 14, "No reptn", 2, 3, 5, 4,
15, 15, "Repetition", 7, 3, 3, 6,
16, 16, "No reptn", 1, 1, 1, 1,
17, 17, "Repetition", 4, 2, 3, 4,
18, 18, "No reptn", 3, 2, 3, 1,
19, 19, "Repetition", 3, 2, 3, 2,
20, 20, "No reptn", 7, 5, 6, 3,
21, 21, "Repetition", 3, 7, 4, 7,
22, 22, "No reptn", 2, 1, 4, 1

Add remaining rows as necessary

)

Pivot the data to long format

data_long <- data %>%
pivot_longer(cols = starts_with("Rating"),
names_to = "Rating_Type",
values_to = "Rating")

View the transformed data

print(data_long)

Do you have a question about this?