[R] Dates and arrays

myshare mraptor at gmail.com
Wed May 13 22:23:09 CEST 2009


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

More information about the R-help mailing list