Hello! I've included a reproducible example of my dataset. It is a very simple dataframe, and my goal is to create a new dataframe that will give the the difference in time that occurs between each x_ (from start to stop) event. For example, in the first two rows, x_begin occurs at 12.5 seconds and ends (x_end) at 15 seconds. I would like to find a way to get the duration of this event (2.5 seconds), and do this for every x/y/z_begin and x/y/z_end that occurs in the dataframe. I'm thinking this can be done with a simple function, however, I am unsure where to start exactly. I hope this makes sense!
> dput(df)
structure(list(EVENT = c("x_begin", "x_end", "x_begin", "x_end",
"y_begin", "y_end", "z_begin", "z_end", "y_begin", "y_end ",
"z_begin", "z_end", "x_begin", "x_end ", "x_begin", "x_end",
"x_begin", "x_end"), TIME = c(12.5, 15, 18, 34.5, 36, 43, 56,
108, 111, 141, 144, 151, 156, 231, 265, 289, 301, 333)), class = "data.frame", row.names = c(NA,
-18L))