I want to copy a value from a row of a data table into another row and another column of this datatable based on some conditions.
Here is the code I tried but at the point with the ????
, I have no idea what I should write there.
dbData[direction == "Coming", GoingTime := (.SD[direction == "Going"][timestamp > ????][order(timestamp)][1])$timestamp, by="eqnr"]
For every row with direction = Coming, I want to get the timestamp of the next row with direction = Going. (for rows with the same value in eqnr)
I hope I could explain my problem. I know, that I can solve the problem with some loops but I want to use the advantages of data.tables