Message-ID: <EEB1B7BA-046C-4114-B821-2063243419CC@comcast.net>
Date: 2011-10-23T23:03:44Z
From: David Winsemius
Subject: Creating 2 week intervals (lubridate)
In-Reply-To: <SNT131-W24C13C5B99793A4F5250AE9CEE0@phx.gbl>
On Oct 23, 2011, at 4:18 PM, <sparklegirl100 at hotmail.com> <sparklegirl100 at hotmail.com
> wrote:
>
> Hello,
> I have a list of dates in which I am going use for a time series
> analysis. I want to break these dates up into 2 week intervals and
> count the number of times a date appears in this interval.
> For example from Nov. 19, 2000 to Dec 2 ,2000 with the data listed
> below I want to return
> Start_date Count2000/11/19 4
> Date: 2000/11/20 2000/11/21 2000/11/19 2000/11/29
> My first approach was toa vector of the two week time periods (like
> below) and then match my dates with the intervals. But this did not
> work.
> DataInterval<-rep(NA, 316)
> TwoWeekint<-function(date) { for (i in 1:316) new.day<-
> i*14 DataInterval[i]<-as.interval(new_period(days=new.day),
> ymd("2000-11-17"))
> }
> Thanks!
(I must note I was very much tempted to ignore this post because of
the mail address.)
See if this helps:
findInterval(as.Date("2000-11-01")+0:60,
seq(from =as.Date("2000-11-20"), to=as.Date("2000-12-31"),
by="2 week")
)
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1
1 2 2 2 2 2 2
[40] 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3
> RK
> [[alternative HTML version deleted]]
Please post in plain text.
>
--
David Winsemius, MD
West Hartford, CT