[R] Dates and arrays
ggrothendieck at gmail.com
Thu May 14 00:51:37 CEST 2009
There is a one line nextfri function defined in the zoo-quickref
vignette and replacing 5 with 1 in its definition will give you next
Monday. The prior Monday is 7 days before that so take the
closest of the two. See R News 4/1 for more about dates.
On Wed, May 13, 2009 at 4:23 PM, myshare <mraptor at gmail.com> wrote:
> I have a and data frame with date-column and some other columns.
> My first question is what is the fastest way to get the index of an
> array if I know the value f.e
>> x = c(4,5,6,7,8)
> so i know the value is 6.. i.e. the index is 3. What I currently do is
> loop over the array, I was thinking if there
> is faster more direct way.
> The next one...is I have a data frame one of the columns is Date based
> (stored as string), as you may be guessed
> I have the date and I want to find the index ;), but here is one more
> The dates are not sequential, but only dates when the day is Mon-Fri
> i.e. for Sat and Sun i don't store information.
> So I have first convert the date I have into the closest Monday.
> Let me give you one example. Let say I have the date 2000/01/01 (Sat),
> now to be able to find any information I have to find the nearest
> Monday in this case it is 2000/01/03 (Mon)..
> So now that I have this new date I can find the index of the element
> in the array where it is stored and from this I can get the real data
> I need.
> In short conversation is from Data ==> nearest Monday ==> index of the
> element in the array where it is stored.
> thank you very much
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help