title: how to create a new column by subtraction of different cells followed by a specific string for each row
body: <p>So I have a data structure that looks like this</p>
  
  <pre><code>       V4  V5     V6     V7  V8    V9    V10 V11   V12  id            date  start yellow
  3   10552 180 yellow     NA  NA           NA  NA       101 20130826T155649      3  10552
  4   19502 150 yellow     NA  NA           NA  NA       101 20130826T155649  12002  19502
  5   28957 130 yellow  30457 160 brake  31457 170   red 101 20130826T155649  22452  28957
  6   46662 160 yellow  47912 185   red     NA  NA       101 20130826T155649  38657  46662
  7   55612 130 yellow  58362 185   red     NA  NA       101 20130826T155649  49112  55612
  8   66567 140 yellow  69167 192   red  69267 194 crash 101 20130826T155649  59562  66567
  9   86532 130 yellow  88182 163 brake  89532 173   red 101 20130826T155649  80027  86532
  10 101337 130 yellow 103087 165   red 103187 167 brake 101 20130826T155649  93282 101337
  </code></pre>
  
  <p>So what happened is I have a really messy table. So you can see, the first column represents the time for the third column, yellow, and the forth column represents the time for the 6th column. What I'm trying to do is that I'm trying to do the time difference between brake and yellow, and then create a new column. And as you can see some rows have no brake. I'm just wondering how to create a new column from this.</p>
  
  <p>the second question is I'm trying to create two new column for crash and no brake, meaning if the row has "crash" or does not have "brake", it would be 1, so I'm guessing I want want to do a True false thing and represent it with 1 and 0 so I can add them up and count. I was thinking doing a for loop but I'm kinda stuck. I'd really appreciate any help </p>