title: After inserting an apply instead of loop
body: <p>I changed my dataset to data.table and I'm using sapply (apply family) but so far that wasn't sufficiant. Is this fully correct?</p>
  
  <p>I already went from this:</p>
  
  <pre><code>library(data.table)
  library(lubridate)
  
  buying_volume_before_breakout &lt;- list()
  for (e in 1:length(df_1_30sec_5min$date_time)) {
  
    interval &lt;- dolar_tick_data_unified_dt[date_time &lt;= df_1_30sec_5min$date_time[e] &amp;
                                             date_time &gt;= df_1_30sec_5min$date_time[e] - time_to_collect_volume &amp;
                                             Type == "Buyer"]
  
    buying_volume_before_breakout[[e]] &lt;- sum(interval$Quantity)
  }
  </code></pre>
  
  <p>To this (created a function and and using sapply)</p>
  
  <pre><code>fun_buying_volume_before_breakout &lt;- function(e) {
    interval &lt;- dolar_tick_data_unified_dt[date_time &lt;= df_1_30sec_5min$date_time[e] &amp;
                                             date_time &gt;= df_1_30sec_5min$date_time[e] - time_to_collect_volume &amp;
                                             Type == "Buyer"]
    return(sum(interval$Quantity))
  }
  buying_volume_before_breakout &lt;- sapply(1:length(df_1_30sec_5min$date_time), fun_buying_volume_before_breakout)
  </code></pre>
  
  <p>I couldn't make my data reproducible but here are some more insights about its structure.</p>
  
  <pre><code>&gt; str(dolar_tick_data_unified_dt)
  Classes ‘data.table’ and 'data.frame':  3120650 obs. of  6 variables:
   $ date_time  : POSIXct, format: "2017-06-02 09:00:35" "2017-06-02 09:00:35" "2017-06-02 09:00:35" ...
   $ Buyer_from : Factor w/ 74 levels "- - ","- - BGC LIQUIDEZ DTVM",..: 29 44 19 44 44 44 44 17 17 17 ...
   $ Price      : num  3271 3271 3272 3271 3271 ...
   $ Quantity   : num  5 5 5 5 5 5 10 5 50 25 ...
   $ Seller_from: Factor w/ 73 levels "- - ","- - BGC LIQUIDEZ DTVM",..: 34 34 42 28 28 28 28 34 45 28 ...
   $ Type       : Factor w/ 4 levels "Buyer","Direct",..: 1 3 1 1 1 1 1 3 3 3 ...
   - attr(*, ".internal.selfref")=&lt;externalptr&gt; 
  
  
  &gt; str(df_1_30sec_5min)
  Classes ‘data.table’ and 'data.frame':  3001 obs. of  13 variables:
   $ date_time                    : POSIXct, format: "2017-06-02 09:33:30" "2017-06-02 09:49:38" "2017-06-02 10:00:41" ...
   $ Price                        : num  3251 3252 3256 3256 3260 ...
   $ fast_small_mm                : num  3250 3253 3254 3256 3259 ...
   $ slow_small_mm                : num  3254 3253 3254 3256 3259 ...
   $ fast_big_mm                  : num  3255 3256 3256 3256 3258 ...
   $ slow_big_mm                  : num  3258 3259 3260 3261 3262 ...
   $ breakout_strength            : num  6.5 2 0.5 2 2.5 0.5 1 2.5 1 0.5 ...
   $ buying_volume_before_breakout: num  1285 485 680 985 820 ...
   $ total_volume_before_breakout : num  1285 485 680 985 820 ...
   $ average_buying_volume        : num  1158 338 318 394 273 ...
   $ average_total_volume         : num  1158 338 318 394 273 ...
   $ relative_strenght            : num  1 1 1 1 1 1 1 1 1 1 ...
   $ relative_strenght_last_6min  : num  1 1 1 1 1 1 1 1 1 1 ...
   - attr(*, ".internal.selfref")=&lt;externalptr&gt; 
  </code></pre>