title: Use dplyr to change an R dataframe from second row across multiple columns
body: <p>I have a large dataframe similar to the toy dataset created below</p>
  
  <pre><code>df&lt;-data.frame("ID"=c("A", "A", "A", "A", "A", "B", "B", "B", "B", "B"), 
  'A_Frequency'=c(1,2,3,4,5,1,2,3,4,5), 'A_Axis'=c(1,2,3,4,5,1,2,3,4,5))
  </code></pre>
  
  <p>The dataframe consists of an ID column and a two columns A_Frequency and A_Axis. 
  I have created a column called A_Slope and filled it using the following for loop</p>
  
  <pre><code>id1&lt;-unique(df$ID)###########Create list of unique IDs to subset the dataframe
  </code></pre>
  
  <p>In this loop we calculate A_Slope value such that the values are calculated subsetting the dataframe df by unique id and then, the values are calculated from the second row to the last row, ignoring the first row in all cases</p>
  
  <pre><code>for( j in id1){
  for( i in 2:nrow(df[df$ID==df$ID[df$ID%in%j],])){
  df$A_Slope[df$ID==df$ID[df$ID%in%j]][i]=10*log(2, 
  10)*log((df$A_Axis[df$ID==df$ID[df$ID%in%j]][i])/
  
  (df$A_Axis[df$ID==df$ID[df$ID%in%j]][i-1]), base = 
  10)/log((df$A_Frequency[df$ID==df$ID[df$ID%in%j]] 
  [i])/(df$A_Frequency[df$ID==df$ID[df$ID%in%j]][i-1]),base = 10 )}}
  </code></pre>
  
  <p>This works well for the toy set. I have a large dataframe with multiple columns. is it possible to use dplyr to do the same using mutate. </p>
  
  <p>Expected Output</p>
  
  <pre><code>        ID A_Frequency A_Axis     A_Slope
       1   A           1      1          NA
       2   A           2      2 3.010299957
       3   A           3      3 3.010299957
       4   A           4      4 3.010299957
       5   A           5      5 3.010299957
       6   B           1      1          NA
       7   B           2      2 3.010299957
       8   B           3      3 3.010299957
       9   B           4      4 3.010299957
       10  B           5      5 3.010299957
  </code></pre>
  
  <p>Note : the two NA values in A_Slope column can be zero also- not necessrily NA</p>