I have a data frame with some values:

ID resid1 resid2 resid3

A 0,5 0,2 -0,2

B 0,1 -0,3 0,2

C 0,3 -0,1 0,1

D 0,3 0 0,2

E 0,1 0,6 -0,8

I would like for every row to find the two columns with the smallest difference in value, and then return the mean of those two values in a separate object. It would look something like this:

ID mean

A 0,35

B 0,25

C 0

D 0,25

E 0,35

Any help appreciated, I am a total newbie and I'm sure there are several ways to do this.