title: How to convert daily frequency dataframe into weekly time series in r?
body: <p>I have a <strong>daily frequency dataframe</strong> which I am trying to convert into <strong>weekly timeseries</strong> to <code>decompose()</code>. I have been able to convert it into <strong>monthly</strong> but same process <strong>doesn't work</strong> as expected for <strong>weekly</strong>.</p>
  <p>Code that I have attempted for both monthly &amp; weekly:</p>
  <p><strong>Data:</strong></p>
  <pre><code>library(tidyverse)
  library(quantmod)
  library(zoo)
  library(xts)
  
  adani_green_df &lt;- read.csv(&quot;https://raw.githubusercontent.com/johnsnow09/covid19-df_stack-code/main/adani_daily_data.csv&quot;) 
  </code></pre>
  <p><strong>Monthly:</strong> (work as expected)</p>
  <pre><code>adani_monthly_zoo &lt;- adani_green_df %&gt;% 
    select(date,CLOSE) %&gt;% 
    set_names(.,c(&quot;date&quot;,&quot;Close&quot;)) %&gt;% 
    
    read.zoo(.,format = &quot;%Y-%m-%d&quot;) %&gt;% 
    to.monthly() %&gt;%  
    Cl() %&gt;% 
    as.ts()
  
  adani_monthly_zoo 
  ########### output #############
  
           Jan     Feb     Mar     Apr     May     Jun     Jul     Aug     Sep     Oct     Nov     Dec
  2018                                           27.15   61.20   57.70   41.00   39.55   46.75   41.90
  2019   35.70   33.05   37.25   40.25   43.10   44.45   46.75   46.20   58.25   89.65  137.20  166.50
  2020  189.45  154.90  153.65  210.25  247.85  358.70  340.65  453.60  737.85  856.25 1120.80 1052.55
  2021 1003.75 1168.05 1104.30 1019.00 1267.25 1116.90  888.20 1066.85 1147.25 1146.35 1291.20 1327.75
  2022 1878.75 1839.10 1913.40 2887.30 1898.80 1929.00 2168.45 2436.70 2347.00
  
  </code></pre>
  <p><strong>Weekly:</strong> (Resulting Data below isn't compiled as it is for <code>monthly</code> in above)</p>
  <pre><code>adani_weekly_zoo &lt;- adani_green_df %&gt;% 
    select(date,CLOSE) %&gt;% 
    set_names(.,c(&quot;date&quot;,&quot;Close&quot;)) %&gt;% 
    
    read.zoo(.,format = &quot;%Y-%m-%d&quot;) %&gt;% 
    to.weekly() %&gt;%  
    Cl() %&gt;% 
    as.ts()
  
  adani_weekly_zoo 
  ########### output #############
  
  Time Series:
  Start = 17704 
  End = 19254 
  Frequency = 1 
     [1]   29.45      NA      NA      NA      NA      NA      NA   27.15      NA      NA      NA      NA
    [13]      NA      NA   30.05      NA      NA      NA      NA      NA      NA   31.50      NA      NA
    [25]      NA      NA      NA      NA   35.30      NA      NA      NA      NA      NA      NA   53.00
    [37]      NA      NA      NA      NA      NA      NA   70.80      NA      NA      NA      NA      NA
    [49]      NA   66.90      NA      NA      NA      NA      NA      NA   55.05      NA      NA      NA
  </code></pre>
  <p><strong>Decompose:</strong>
  <code>decompose()</code> is working on monthly timeseries that is created above but not working on weekly timeseries.</p>
  <pre><code># works
  adani_monthly_zoo %&gt;% 
    decompose() %&gt;% 
    plot()
  </code></pre>
  <pre><code># doesn't work
  adani_weekly_zoo %&gt;% 
    decompose() %&gt;% 
    plot()
  </code></pre>
  <blockquote>
  <p>Error in decompose(.) : time series has no or less than 2 periods</p>
  </blockquote>