I have a dataframe of ids and timestamps. I'd like to calculate the difference between each sequential timestamp for an individual id.
My dataframe looks like this:
id time
Alpha 1
Alpha 4
Alpha 7
Beta 5
Beta 10
I'm trying to add a column like time.difference
below:
id time time.difference
Alpha 1 NA
Alpha 4 3
Alpha 7 4
Beta 5 NA
Beta 10 5
Is there a clean way to do this using dplyr? (or tidyr or something else that's easier to read than vanilla R?)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…