How do I convert date to number of days, starting from the first day of the year.
How do I convert the following to the expected result below?
Dat
Here's a solution using the lubridate package:
library(lubridate) x <- c("02/01/2000", "20/02/2000", "12/12/2000", "13/01/2001") date <- dmy(x) days <- yday(date) - 1 # so Jan 1 = day 0 total_days <- cumsum(days)