I am trying to create a new variable n that calculates the number of days between 2 dates in the same column. What I want to achieve is shown in the table below:
The code I have written is giving me zeros throughout. I have checked the class and its a Date. What could be this issue.
historical_sonia <- historical_sonia %>% arrange(newdate) %>% # sort by date mutate(n = as.numeric(newdate - lag(newdate)))