title: How to order and mark duplicated rows at the same time
body: <p>I am looking to make a new variable to mark which of my data is duplicated, selecting the oldest datapoint to be the &quot;original&quot;. My dataframe is ordered by date, but by ID.</p>
  <pre><code>ID      Name        Number         Datetime (dd/mm/yyy/hh/MM)
  1       ace         114            15.03.2019 15:26
  2       bert        197            18.03.2019 07:28
  3       vance       245            16.03.2019 14:03
  4       chad        116            17.03.2019 02:02
  5       chad        116            18.03.2019 18:23
  6       ace         114            12.03.2019 23:15
  
  </code></pre>
  <p>Ordering the dataframe works and selecting the duplicated lines also works, but not in combination, which leads to the originals not being the first presentation. Even if I order the dataframe before marking the represenation the dataframe is seems to be unordered for the next command and linking the two commands with %&gt;% is not working.</p>
  <pre><code>df %&gt;% arrange(Datetime) 
  df$representations &lt;- if_else(duplicated(df$number, .keep_all =TRUE), 1, 0)
  
  df$represntations &lt;- df %&gt;%
     arrange(Datetime) %&gt;%
     if_else(duplicated(df$number, .keep_all =TRUE), 1, 0)
  </code></pre>
  <p>How can i be sure, that the the originals will be the first datapoint to the number (like this)?</p>
  <pre><code>ID      Name        Number         Datetime (dd/mm/yyy/hh/MM)  representation
  1       ace         114            15.03.2019 15:26            1
  2       bert        197            18.03.2019 07:28            0
  3       vance       245            16.03.2019 14:03            0
  4       chad        116            17.03.2019 02:02            0
  5       chad        116            18.03.2019 18:23            1
  6       ace         114            12.03.2019 23:15            0
  </code></pre>