[R] Create previous dates from date with consideration of leap year
Kuma Raj
pollaroid at gmail.com
Thu Dec 11 16:54:27 CET 2014
Dear R Community,
I wish to create 5 preceding dates from the date variable by ID. How
could I create such dates? The code should consider leap year.
Thanks
Sample data follows:
structure(list(id = 1:12, date = structure(c(9L, 6L, 11L, 8L,
7L, 5L, 4L, 3L, 12L, 1L, 10L, 2L), .Label = c("01feb2003", "03mar2008",
"04feb2008", "07jul1991", "07jun2010", "13feb2005", "18dec1991",
"22sep2005", "27apr1993", "29jan2009", "29may2002", "31jan2005"
), class = "factor"), case = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L)), .Names = c("id", "date", "case"), class =
"data.frame", row.names = c(NA,
-12L))
More information about the R-help
mailing list