I am working with a list of dates and I would like to replace each date with the one that comes after, ie. 1/1/07 will become 1/5/07, 1/5/07 will become 1/7/07, etc. The number of days between my dates always varies, so I can't just increase each one by 5 days or so. Does anyone know of a way I can do this in R? thank you [[alternative HTML version deleted]]
Hi Alina, ? You can always write a loop in R to do this: # A function to shift values in an vector shift = function(y) { ?cnt = length(y) - 1 ?m=vector(mode = "numeric",length = cnt)? ?for (j in 1:cnt) { ?m[j] = y[j+1]} ?m } ? Regards, Indrajit ________________________________ From: Alina Sheyman <alinashe at gmail.com> To: r-help at r-project.org Sent: Thursday, January 22, 2009 2:48:42 AM Subject: [R] Replacing dates with consecutive observations I am working with a list of dates and I would like to replace each date with the one that comes after, ie. 1/1/07 will become 1/5/07, 1/5/07 will become 1/7/07, etc. The number of days between my dates always varies, so I can't just increase each one by 5 days or? so. Does anyone know of a way I can do this in R? thank you ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Henrique Dallazuanna
2009-Jan-22 10:21 UTC
[R] Replacing dates with consecutive observations
Try this also: x <- seq(as.Date("2008-01-01"), as.Date("2008-12-31"), l = 10) as.Date(embed(matrix(x), 2)[,1], origin = "1970-01-01") On Wed, Jan 21, 2009 at 7:18 PM, Alina Sheyman <alinashe@gmail.com> wrote:> I am working with a list of dates and I would like to replace each date > with > the one that comes after, ie. 1/1/07 will become 1/5/07, 1/5/07 will become > 1/7/07, etc. The number of days between my dates always varies, so I can't > just increase each one by 5 days or so. Does anyone know of a way I can do > this in R? > > thank you > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]