Despite using R and dplyr on a regular basis, I encountered the issue of not being able to calculate the sum of the absolute differences between all columns:
sum_diff=ABS(A-B)+ABS(B-C)+ABS(C-D)...
| A | B | C | D | sum_diff |
|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 3 |
| 2 | 1 | 3 | 4 | 4 |
| 1 | 2 | 1 | 1 | 2 |
| 4 | 1 | 2 | 1 | 5 |
I know I could iterate using a for loop over all columns, but given the size of my data frame, I prefer a more elegant and fast solution.
Any help?
Thank you