title: How can I calculate the percentage change within a group for multiple columns in R?
body: <p>I have a data frame with an ID column, a date column (12 months for each ID), and I have 23 numeric variables. I would like to obtain the percentage change by month within each ID. I am using the quantmod package in order to obtain the percent change.</p>
  
  <p>Here is an example with only three columns (for simplicity):</p>
  
  <pre><code>ID Date V1 V2 V3
  1  Jan   2  3  5
  1  Feb   3  4  6
  1  Mar   7  8  9
  2  Jan   1  1  1
  2  Feb   2  3  4
  2  Mar   7  8   8
  </code></pre>
  
  <p>I tried to use dplyr and the summarise_each function, but that was unsuccessful. More specifically, I tried the following (train is the name of the data set):</p>
  
  <pre><code>library(dplyr)
  library(quantmod)
  
  group1&lt;-group_by(train,EXAMID)
  
  foo&lt;-function(x){
    return(Delt(x))
  }
  
  summarise_each(group1,funs(foo))
  </code></pre>
  
  <p>I also tried to use the do function in dplyr, but I was not successful with that either (having a bad night I guess!). </p>
  
  <p>I think that the issue is the Delt function. When I replace Delt with the sum function:</p>
  
  <pre><code>foo&lt;-function(x){
        return(sum(x))
      }
  summarise_each(group1,funs(foo))
  </code></pre>
  
  <p>The result is that every variable is summed across the date for each ID. So how can about the percentage change month-over-month for each ID?</p>