I want to calculate how much time has passed since something happened.
Given the following, you can see that the light is turned on in some cases, but not all the time. I want to normalize the data to transfer it to the neural network.
library(data.table) d<-data.table( date = c("6/1/2013", "6/2/2013","6/3/2013","6/4/2013"), light = c(TRUE,FALSE,FALSE,TRUE) ) d date light 1: 6/1/2013 TRUE 2: 6/2/2013 FALSE 3: 6/3/2013 FALSE 4: 6/4/2013 TRUE
what I would like to calculate is another column that shows the "distance" to the last occurrence.
therefore, for the data above: the first line, since it should be zero, the second line should be 1 third line, should be 2 fourth line, should be zero
source share