title: How to calculate daily percent change and three day percent change R?
body: <p>I have a datframe with that I want to calculate the percent change day by day and also over three days but when I do it the results don't really seem right. </p>
  
  <pre><code>ads &lt;- data.frame(ad = c(ad1, ad1, ad1, ad1, ad2, ad2, ad2, ad3, ad3, ad3), 
                    date = c("11-10", "11-11", "11-12", "11-13", "11-10", "11-11", "11-12", "11-10", "11-11", "11-12"), 
                    likes = c(20, 30, 18, 5, 34, 68, 55, 44, 33, 20),
                    comments = c(21, 22, 10, 1, 10, 43, 24, 34, 21, 11))
  </code></pre>
  
  <p>so for I have this: </p>
  
  <pre><code>daily_pct &lt;- function(x) x/lag(x)
  three_pct &lt;- function(x) x/lag(x ,k = 3)
  
  daily_pct_change &lt;- ads %&gt;%
       mutate_each(funs(daily_pct), c(likes,comments))
  
  three_pct_change &lt;- ads %&gt;% 
       mutate_each(funs(three_pct), c(likes, comments))
  </code></pre>
  
  <p>Am I doing this correctly? I can't figure out how to get the three day one to work either. Thanks! </p>