[R] Generating sequence of dates

jim holtman jholtman at gmail.com
Wed Oct 28 13:05:10 CET 2009


try this:

> current = as.Date("2009/10/25")
> start <- seq(current, by='-1 week', length=2)[2]
> seq(start, by='1 week', length=10)
 [1] "2009-10-18" "2009-10-25" "2009-11-01" "2009-11-08" "2009-11-15"
"2009-11-22" "2009-11-29" "2009-12-06" "2009-12-13"
[10] "2009-12-20"
>


On Wed, Oct 28, 2009 at 7:57 AM, Vadlamani, Satish {FLNA}
<SATISH.VADLAMANI at fritolay.com> wrote:
> Hello All:
> I have the following question
>
> # instantiate a date
> current = as.Date("2009/10/25")
>
> #generate a sequence of dates in the future
> future_dates = seq(current,by='1 week',length=53)
>
> Question: How to generate a sequence of past dates starting one week in the past relative to the current date. Obviously, what I wrote below is not correct. I think I can write a for loop and push each value into a vector. Is this the best way? Thanks.
>
> Satish
>
>
> past_dates = seq(current,by=-'1 week',length=156)
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list