Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove identical sequence of same numbers from data frame/vector
    primarykey
    data
    text
    <p>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? </p> <p>I have started by creating bins:</p> <pre><code>split(data.frame[dataFrame$def == 1, ], dataFrame[dataFrame$def == 1, 'coKey]) </code></pre> <p>where the 'coKey' is the "company code". </p> <p>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.</p> <p>Thanks a lot for you help, much appreciated. </p> <p>Here is sample data.</p> <pre><code>dataFrame &lt;- 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") </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload