Question: I would highly appreciate if somebody could help me out with this. This looks simple but I have no clue how to go about it. 

I am trying to work out the percentage change in one row with respect to the previous one. For example: my data frame looks like this:

```
day          value  

 1           21
 2           23.4
 3           10.7
 4           5.6 
 5           3.2
 6           35.2  
 7           12.9
 8           67.8
 .            .
 .            .  
 .            .
 365         27.2

```

What I am trying to do is to calculate the percentage change in each row with respect to previous row. For example:

```
 day              value   

 1                  21
 2          (day2-day1/day1)*100
 3          (day3-day2/day2)*100
 4          (day4-day3/day3)*100 
 5          (day5-day4/day4)*100
 6          (day6-day5/day5)*100  
 7          (day7-day6/day6)*100
 8          (day8-day7/day7)*100
 .                  .
 .                  .  
 .                  .
 365        (day365-day364/day364)*100

```

and then print out only those days where the there was a percentage increase of >50% from the previous row

Many thanks

Answer: 
Use [`diff`](http://stat.ethz.ch/R-manual/R-patched/library/base/html/diff.html):

```
value <- 100*diff(value)/value[2:length(value)]

```
You're looking for the `diff`function :

```
x<-c(3,1,4,1,5)
diff(x)
[1] -2  3 -3  4

```