I am trying to find difference in the first and last value of for a set of values in a given column in R. The example data table is
V1 V2
A 2
B 4
A 3
C 1
D 2
B 4
A 5
The output should take the first and last occurrence and give the result
V1 V2
A 3
B 0
C 1
D 2
I am confused as to which function to use to get to the result in r.