title: Resampling with replacement
body: <p>I am trying to get the (bootstrapped) input data for my model. </p>
  
  <p>Source file: <a href="https://www.dropbox.com/s/dudzxhozr50uhr7/EddyData_2010.csv?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/dudzxhozr50uhr7/EddyData_2010.csv?dl=0</a></p>
  
  <pre><code>library("dplyr")
  library("readr")
  library("reshape2")
  library("ggplot2")
  
  sub &lt;- read_csv("EddyData_2010.csv", 
                  col_types = list(col_integer(), col_integer(), col_double(),
                                   col_double(), col_double(), col_double(),
                                   col_double(), col_double(), col_double(),
                                   col_double(), col_double(), col_double()),
                  col_names = c("Year", "DoY", "Hour", "NEE", "LE", "H", "Rg",
                                "Tair", "Tsoil", "rH", "Ustar", "VPD")) %&gt;%
    filter(DoY == 170) %&gt;%
    mutate(hour = 1:48) %&gt;%
    select(NEE:hour)
  
  # Number of resampling 
  n_resempling &lt;- 1000 
  result_resampling &lt;- NULL
  
  # Do the resampling
  for (i in 1:n_resempling) {
    result_resampling &lt;- sample(48, 48, replace = T) %&gt;%
      slice(sub, .) %&gt;%
      mutate(resempling_number = i) %&gt;%
      bind_rows(. , result_resampling)
  }
  </code></pre>
  
  <p>This generates a resampling with replacement such as</p>
  
  <p><a href="https://i.stack.imgur.com/eDKXm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eDKXm.png" alt="enter image description here"></a></p>
  
  <p>The output shows 1000 bootstraps resampled with replacement along 48 half-hours that a day have. </p>
  
  <p>Here is my problem:</p>
  
  <p>The resampling with replacement is randomly mixing up half-hours along the day without any kind of control. For instance, I am not interested in mixing up half-hours at night and half-hours during the days. The results leads to weird calculations afterwards. Is there any possibility to code this in such a way I define what is allowed and what is not?</p>
  
  <p>Example:</p>
  
  <ul>
  <li>it is only allowed to resample from 10pm till 5pm</li>
  <li>night hours cannot be resampled with day hours (and vice versa)</li>
  </ul>