Note that there are some explanatory texts on larger screens.

plurals
  1. POroll data.table both forwards and backwards simultaneously
    primarykey
    data
    text
    <p>This is related to the previous question on SO: <a href="https://stackoverflow.com/questions/18984179/roll-data-table-with-rollends">roll data.table with rollends</a></p> <p>Given the data...</p> <pre><code>library(data.table) dt1 = data.table(Date=seq(from=as.Date("2013-01-03"), to=as.Date("2013-06-27"), by="1 week"), key="Date")[, ind:=.I] dt2 = data.table(Date=seq(from=as.Date("2013-01-01"), to=as.Date("2013-06-30"), by="1 day"), key="Date") </code></pre> <p>I try to <strong>carry the weekly datapoints one day forward and backward</strong> ...</p> <pre><code>dt1[dt2, roll=1][dt2, roll=-1] </code></pre> <p>...but only the first roll join <em>(forward)</em> seems to work and <code>roll=-1</code> is ignored:</p> <pre><code> Date ind 1: 2013-01-01 NA 2: 2013-01-02 NA 3: 2013-01-03 1 4: 2013-01-04 1 5: 2013-01-05 NA --- 177: 2013-06-26 NA 178: 2013-06-27 26 179: 2013-06-28 26 180: 2013-06-29 NA 181: 2013-06-30 NA </code></pre> <p>The same effect when I reverse the order:</p> <pre><code>dt1[dt2, roll=-1][dt2, roll=1] Date ind 1: 2013-01-01 NA 2: 2013-01-02 1 3: 2013-01-03 1 4: 2013-01-04 NA 5: 2013-01-05 NA --- 177: 2013-06-26 26 178: 2013-06-27 26 179: 2013-06-28 NA 180: 2013-06-29 NA 181: 2013-06-30 NA </code></pre> <p>I would like to achieve:</p> <pre><code> Date ind 1: 2013-01-01 NA 2: 2013-01-02 1 3: 2013-01-03 1 4: 2013-01-04 1 5: 2013-01-05 NA --- 177: 2013-06-26 26 178: 2013-06-27 26 179: 2013-06-28 26 180: 2013-06-29 NA 181: 2013-06-30 NA </code></pre> <p><strong>EDIT:</strong> I am using the fresh <strong>data.table version 1.8.11</strong>, note session details:</p> <pre><code>sessionInfo() R version 3.0.0 (2013-04-03) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] data.table_1.8.11 loaded via a namespace (and not attached): [1] plyr_1.8 reshape2_1.2.2 stringr_0.6.2 tools_3.0.0 </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload