title: How to randomly assign a user id to a different date using R
body: <p>I have such dataset</p>
  <pre><code>mydata=structure(list(SAP = c(&quot;S985&quot;, &quot;S985&quot;, &quot;S985&quot;, &quot;S985&quot;, &quot;S985&quot;, 
  &quot;S985&quot;, &quot;S985&quot;, &quot;S985&quot;), code = c(50000690L, 50000690L, 50000690L, 
  50000690L, 801L, 50000690L, 50000690L, 50000690L), dt_start = c(&quot;18.01.2022 8:00&quot;, 
  &quot;18.01.2022 12:00&quot;, &quot;18.01.2022 12:00&quot;, &quot;18.01.2022 10:00&quot;, &quot;22.01.2022 10:00&quot;, 
  &quot;22.01.2022 10:00&quot;, &quot;22.01.2022 12:00&quot;, &quot;22.01.2022 12:00&quot;), 
      dt_end = c(&quot;18.01.2022 10:00&quot;, &quot;18.01.2022 22:00&quot;, &quot;18.01.2022 22:00&quot;, 
      &quot;18.01.2022 20:00&quot;, &quot;22.01.2022 20:00&quot;, &quot;22.01.2022 20:00&quot;, 
      &quot;22.01.2022 22:00&quot;, &quot;22.01.2022 22:00&quot;), person_number = c(938541L, 
      938541L, 938541L, 938541L, 754105L, 867801L, 865394L, 938541L
      )), class = &quot;data.frame&quot;, row.names = c(NA, -8L))
  </code></pre>
  <p>In this dataset, we see that there is column  <code>person_number=938541</code> who have only one date <code>18.01</code> in the columns <code>dt start</code> and <code>dt end</code>. This means that on this date he works alone (do not pay attention to duplicates in the date, this is not important now). But in general, we see that whe have 4 unique person_number (persons).</p>
  <pre><code>754105
  867801
  865394
  938541
  </code></pre>
  <p>How to do  that if it so happened that on some date one person works, then we are looking for a all unique personal_number, and we sign randomly anyone on the date where work just one personal_number. For example desired result like this</p>
  <pre><code>SAP code           dt_start                    dt_end         person_number
  S985    50000690    18.01.2022 8:00     18.01.2022 10:00    938541
  S985    50000690    18.01.2022 12:00    18.01.2022 22:00    938541
  S985    50000690    18.01.2022 12:00    18.01.2022 22:00    938541
  S985    50000690    18.01.2022 10:00    18.01.2022 20:00    938541
  **S985  50000690    18.01.2022 12:00    18.01.2022 22:00    865394**
  S985    801         22.01.2022 10:00    22.01.2022 20:00    754105
  S985    50000690    22.01.2022 10:00    22.01.2022 20:00    867801
  S985    50000690    22.01.2022 12:00    22.01.2022 22:00    865394
  S985    50000690    22.01.2022 12:00    22.01.2022 22:00    938541
  </code></pre>
  <p>randomly i chose <code>865394</code> and pasted it on 18.01 date.So on 18.01 date two people work instead of one.
  Your help will be appreciated. Thank you.</p>