I have data that looks like this:
library(tidyverse)
data <- tibble(id = 1:3,
events = c("E1/E2/E3", "E3/E2", "E1"),
times = c("10/20/30", "35/20", "15"))
For each id there is a column that contains a list of events separated by /, and a list of times for those events also separated by /. The events and times match by position. I want to convert this data into a tidy format where I have a column with the event name and time, with id repeating for each separate event:time combo.
My desired format looks like this:
desired <- tibble(id = c(1,1,1,2,2,3),
event = c("E1", "E2", "E3", "E3", "E2", "E1"),
time = c(10, 20, 30, 35, 20, 15))
I thought about this conceptually using pivot long, but I am unsure how to do this as I am almost pivoting within column values. Also tried splitting the columns into multiple, but I run into the problem that there are different orders and amounts of event per id. Thanks for the help!
Edit: There was a similar questions asked on concept; however, this question already identifies a function to do this in the title, and may be difficult to find: tidyr use separate_rows over multiple columns