title: Find corresponding "father" row in dataframe
body: <p>I've a dataframe with A and B rows. Bs are children of A.</p>
  <p>For each B line I need to write the corresponding A father.</p>
  <p>The number of Bs for each A is variable.</p>
  <p>I'm thinking about a <code>for</code> cycle but I don't think it's the right way....</p>
  <p>Here a simplified example:</p>
  <pre><code>&gt; df &lt;- data.frame(Index=c(1:9),
  +                  Type=c(&quot;A&quot;,&quot;B&quot;,&quot;A&quot;,&quot;B&quot;,&quot;B&quot;,&quot;B&quot;,&quot;A&quot;,&quot;B&quot;,&quot;B&quot;),
  +                  Aindex=&quot;&quot;)
  &gt; df
    Index Type Aindex
  1     1    A       
  2     2    B       
  3     3    A       
  4     4    B       
  5     5    B       
  6     6    B       
  7     7    A       
  8     8    B       
  9     9    B       
  </code></pre>
  <p>This is the result I'd like to have:</p>
  <pre><code>&gt; df2
    Index Type Aindex
  1     1    A       
  2     2    B      1
  3     3    A       
  4     4    B      3
  5     5    B      3
  6     6    B      3
  7     7    A       
  8     8    B      7
  9     9    B      7
  </code></pre>