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

```
Using data.table

```
 dt[ , new:= column_b /  shift(column_a)]

  column_a column_b       new
1:       10        2        NA
2:       30        3 0.3000000
3:       40        4 0.1333333

```