title: Values from previous year
body: <p>is there any way to get a new column containing values from the previous years from the same table?</p>
  <p>DATA:
  library(data.table)</p>
  <pre><code>table = data.table( Date =c( &quot;01/01/2022&quot;, &quot;01/10/2021&quot;, &quot;01/07/2021&quot;, &quot;01/04/2021&quot;, &quot;01/01/2021&quot;, &quot;01/10/2020&quot;, &quot;01/07/2020&quot;),
                      Hospital = &quot;Hospital 1&quot;,
                      Patients = c(13,11,9,7,5,3,1) 
                      )
  </code></pre>
  <p>RESULT:</p>
  <pre><code>result = data.table( Date =c( &quot;01/01/2022&quot;, &quot;01/10/2021&quot;, &quot;01/07/2021&quot;, &quot;01/04/2021&quot;, &quot;01/01/2021&quot;, &quot;01/10/2020&quot;, &quot;01/07/2020&quot;),
                       Hospital = 'Hospital 1',
                      Patients = c(13,11,9,7,5,3,1),
                      Patients_previous_year = c(5,3,1,NA,NA,NA,NA) )
  </code></pre>