I have a data frame called data
. It looks like this:
Train Local Arrival
A1 Yes 1
A2 Yes 3
A3 Yes 5
A4 No 2
A5 No 3
I come to this table by doing the following:
data <- fread(file) %>%
select(Train, Local, Arrival) %>%
group_by(Local)
Now, I know that I can calculate the differences between the arrival times by using diff()
, this however does not take into consideration when the group type changes, e.g. A3 - A5.
How could I use the function so that I get two series of differences, one where Local=="Yes"
and another one for Local =="No"
?
Expected output:
sol_yes <- 2,3
sol_no <- 1