title: R: Combine rows with same ID
body: <p><strong>Edit:</strong> I changed Var4 to a string value as my question was not precise enough about my data and therefore answers were failing because of invalid types. Sorry for that</p>
  <p>this is my first question here and I hope someone can help me.</p>
  <p>I have the following data set:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">ID</th>
  <th style="text-align: left;">Date</th>
  <th style="text-align: left;">N_Date</th>
  <th style="text-align: left;">Var1</th>
  <th style="text-align: left;">Var2</th>
  <th style="text-align: left;">Var3</th>
  <th style="text-align: left;">Var4</th>
  <th style="text-align: left;">type</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">1</td>
  <td style="text-align: left;">4.7.22</td>
  <td style="text-align: left;">50000</td>
  <td style="text-align: left;">12</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">normal</td>
  </tr>
  <tr>
  <td style="text-align: left;">1</td>
  <td style="text-align: left;">4.7.22</td>
  <td style="text-align: left;">50000</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">23</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">normal</td>
  </tr>
  <tr>
  <td style="text-align: left;">1</td>
  <td style="text-align: left;">4.7.22</td>
  <td style="text-align: left;">50000</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">5</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">normal</td>
  </tr>
  <tr>
  <td style="text-align: left;">1</td>
  <td style="text-align: left;">4.7.22</td>
  <td style="text-align: left;">50000</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">asd</td>
  <td style="text-align: left;">normal</td>
  </tr>
  <tr>
  <td style="text-align: left;">2</td>
  <td style="text-align: left;">4.7.22</td>
  <td style="text-align: left;">50000</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">2</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">normal</td>
  </tr>
  <tr>
  <td style="text-align: left;">3</td>
  <td style="text-align: left;">5.7.22</td>
  <td style="text-align: left;">20000</td>
  <td style="text-align: left;">7</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">NA</td>
  <td style="text-align: left;">normal</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>My goal is to have just one row for each ID. So what I want R to do, is to shift the Var column values for each ID up or somehow combine them. As you can see, at the moment, there is never more than one value in a Var column for each row. So it should be easy to rewrite the NAs with the corresponding &quot;real value&quot;. I also found similiar questions but the answer did not help in my case:</p>
  <p><a href="https://stackoverflow.com/questions/51523082/how-to-combine-rows-with-the-same-identifier-r">How to combine rows with the same identifier R?</a></p>
  <p>I think the problem in my case is, that I have columns like &quot;date&quot;, &quot;N_date&quot; (which is the number of observations on that date) and &quot;type&quot;. In these cases my code should see, that it is exactly the same value for the corresponding ID, and just take the first value for example.</p>
  <p>So that in the end I just have 3 rows with same number of columns, containing all information.</p>
  <p>Thank you very much for anyone who has an idea how to solve this.</p>