Folks,

I have a dataframe comprising a column of dates and a column of signals (-1, 
0, 1) that looks something like this:

30/01/2007      0
31/01/2007      -1
01/02/2007      -1
02/02/2007      -1
03/02/2007      1
04/02/2007      1
05/02/2007      1
06/02/2007      1
07/02/2007      1
08/02/2007      1
09/02/2007      0
10/02/2007      0
11/02/2007      0
12/02/2007      1
13/02/2007      1
14/02/2007      1
15/02/2007      0
16/02/2007      0

What I need to do is for each signal *in reverse chronological order* to 
find the date that it first appeared. So, for the zero on 16/02/2007 and 
15/02/2007, the 'inception' date would be 15/02/2007, because the day 
before, the signal was 1. Likewise, the 'inception' date for the signal 1 on 
08/02/2007 and the five days prior, would be 03/02/2007. I need to create a 
structure of inception dates that would finally look as follows:

-1      31/01/2007
-1      31/01/2007
-1      31/01/2007
1       03/02/2007
1       03/02/2007
1       03/02/2007
1       03/02/2007
1       03/02/2007
1       03/02/2007
0       09/02/2007
0       09/02/2007
0       09/02/2007
1       12/02/2007
1       12/02/2007
1       12/02/2007
0       15/02/2007
0       15/02/2007

Is there a clever way of doing this? My sadly C-oriented upbringing can only 
think in terms of for-loops.

Thanks!

Murali

_________________________________________________________________
The average US Credit Score is 675. The cost to see yours: $0 by Experian.

______________________________________________
R-help@stat.math.ethz.ch 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.

Reply via email to