I have a dataframe where some rows are follow-ups of other other rows (completing each other) which I would like to combine into one row. Take the following example
+-------+-------------+-----------+-----+---------+
| rowID | name        | address   | age | firstId |
+-------+-------------+-----------+-----+---------+
| 1     | Bert        |           | 60  |         |
+-------+-------------+-----------+-----+---------+
| 2     | Ernie       | Berlin    | 72  |         |
+-------+-------------+-----------+-----+---------+
| 3     | Bert Sesame | Amsterdam |     | 1       |
+-------+-------------+-----------+-----+---------+
The 3rd rowId refers back to the 1st RowId which in turn would make Bert 60 years old. Meanwhile the second row has no firstId (a row to follow-up on) and should be left as is.
Some columns can be filled in on both rows and I would like to take the row which has the firstID field filled in (thus the latest row). For example the 3rd row would have the name "Bert Sesame", i would like to use the name "bert sesame" in that case, the row with a firstId value.
The end dataframe would be
+-------+-------------+-----------+-----+---------+
| rowID | name        | address   | age | firstId |
+-------+-------------+-----------+-----+---------+
| 2     | Ernie       | Berlin    | 72  |         |
+-------+-------------+-----------+-----+---------+
| 3     | Bert Sesame | Amsterdam | 60  | 1       |
+-------+-------------+-----------+-----+---------+
How do I achieve this?
I have looked at questions such as this. Merge two rows in data.frame
But this refers to all rows by grouping them together. I only want to merge / combine rows which specifically refer to other rows.
 
    