"for" loop not working
<p>I am trying to isolate some values from a data frame
example:</p>

<pre><code>test_df0&lt;- data.frame('col1'= c('string1', 'string2', 'string1'),
'col2' = c('value1', 'value2', 'value3'),
'col3' = c('string3', 'string4', 'string3'))
</code></pre>

<p>I want to obtain a new dataframe with only unique strings from col1, and the relevant strings from col3 (which will be identical for rows with identical col1.
This is the loop I wrote, but I must be doing some blunt mistake:</p>

<pre><code>test_df1&lt;- as.data.frame(matrix(ncol= 2, nrow=0))
colnames(test_df1)&lt;- c('col1', 'col3')
for (i in unique(test_df0$col1)){
  first_matching_row&lt;- match(x = i, table = test_df0$col1)
  temp_df&lt;-
    data.frame('col1'= i,
               'col3'= test_df0[first_matching_row, 'col3'])
  rbind(test_df1, temp_df)}
</code></pre>

<p>The resulting test_df1 though is empty. Cannot spot the mistake with the loop, I would be grateful for any suggestion.</p>

<p>Edit: the for loop is working, if its last line is <code>print(temp_df)</code> instead of the rbind command, I get the correct results. I am not sure why the rbind is not working</p>