[R] Generate sequence of date based on a group ID

Kuma Raj pollaroid at gmail.com
Wed Oct 8 09:57:46 CEST 2014


I want to generate a sequence of date based on a group id(similar IDs
should have same date). The id variable contains unequal observations
and the length of the data set also varies.  How could I create a
sequence that starts on specific date (say January 1, 2000 onwards)
and continues until the end without specifying length?


Sample data follows:

df<-structure(list(id = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,

3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L), out1 = c(0L,

0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L,

0L, 1L, 0L, 0L, 0L, 1L)), .Names = c("id", "out1"), class =
"data.frame", row.names = c(NA,

-23L))



More information about the R-help mailing list