I am wanting to create a startime and endtime column from my current datetime column in R. My data has been grouped by ID.
Here is the data:
ID DATETIMEUTC
A 12/17/2019 9:46:04 PM
A 12/17/2019 9:46:05 PM
A 12/18/2019 2:34:56 AM
A 12/18/2019 2:34:58 AM
I am wanting this outcome:
ID StartTime EndTime
A 12/17/2019 9:46:04 PM 12/17/2019 9:46:05 PM
A 12/18/2019 2:34:56 AM 12/18/2019 2:34:58 AM
Here is the code that I am writing to try and achieve this:
library(dplyr)
df %>%
group_by(id) %>%
mutate(start=date, stop=lead(start, default=end[1]))
This command is not yielding the desired result. I am still researching this. Any suggestions is greatly appreciated!
Tanisha Hudson