I have a dataframe,
df = ( a = 1:0.1:10,
b = 1:0.2:20
)
I would like to operate on the dataframe elements and find the difference of each element with respect to its previous element in columns a and b and store the results in the new columns da and db.
Example
a b da db
1 1 Nan Nan
1.1 1.2 0.1 0.2
. . . .
. . . .
Please suggest a solution to this problem.
Thanks in advance!