Question: ```
column a   column b
 10          2
 30          3
 40          4

```

in r, how can i divide column B's value by previous row value of column A

like 3/10 and 4/30

Answer: 
Using Base R:

```
 transform(dat,new=c(NA,head(column_a,-1))/column_b)
  column_a column_b      new
1       10        2       NA
2       30        3 3.333333
3       40        4 7.500000

```
You can use `lead()` and `lag()`from `dplyr`, which finds the next or previous value in a vector:

```
library(dplyr)
df <- data.frame(a = c(10, 30, 40),
                 b = c(2, 3, 4)) 

```

First option: `lead()`

```
lead(df$b) / df$a

```

returns

```
[1] 0.3000000 0.1333333        NA

```

Second option: `lag()`

```
df$b / lag(df$a)

```

returns 

```
[1]        NA 0.3000000 0.1333333

```