I have a dataset, which contains columns of "years", "code of the company" and "def - whether company defaulted". The problem I have is that the column of "def" contains a sequence of "1" for default. Those "1" is for all the years the company is in operation. So for instance the firm operates from 1990 and went out of business in the year 2000. The column contains 10 times "1" even though the company defaulted in the last year i.e. year 2000. So I should have instead column for this particular "company code" only "1" default entry for the year 2000 and not throughout the years 1990-2000. How can I remove the sequence of "1" from the column "def" (I have it now as data.frame) and just leave the last entry of "1" as actual default? 

I have started by creating bins:

```
split(data.frame[dataFrame$def == 1, ], dataFrame[dataFrame$def == 1, 'coKey]) 

```

where the 'coKey' is the "company code". 

I could not clean the data by leaving the last observation and neither was I successful in reversing the bins into the original data frame as the procedure to do so was too obsolete.

Thanks a lot for you help, much appreciated. 

Here is sample data.

```
dataFrame <- structure(list(fyear = 1981:1986, 
   gvkey = c(1004L, 1004L, 1004L, 1004L, 1004L, 1004L), 
   def = structure(c(1L, 1L, 1L, 1L, 1L, 1L ), 
   .Label = c("0", "1"), class = "factor")), 
   .Names = c("fyear", "coKey", "def"), 
   row.names = c(NA, 6L), class = "data.frame")

```