I have data with start times and end times of certain events (subjects gazing at an object called Center).
test <- data.frame(
gaze_at = c("Center", "Center", "Center"),
start = c(1.4, 2.5, 4.4),
end = c(1.66, 2.8, 4.93)
)
I would like to 'fill up' the dataframe with the start times and end times of the participant not gazing at Center by inserting these times into every second row of the dataframe. The desired output is this:
test1 <- data.frame(
gaze_at = c("Center", "NonCenter", "Center", "NonCenter", "Center", "NonCenter"),
start = c(1.4, 1.66, 2.5, 2.8, 4.4, 4.93),
end = c(1.66, 2.5, 2.8, 4.4, 4.93, NA)
)
I've tried using tidyverse::unnest but that didn't work. How can this transformation be achieved?