So I have this big data set with 32 variables and I need to work with relative values of these variables using all possible subtractions among them. Ex. var1-var2...var1-var32; var3-var4...var3-var32, and so on. I'm new in R, so I would like to do this without going full manually on the process. I'm out of idea, other than doing all manually. Any help appreciated! Thanks!
Ex: df_original
id | Var1 | Var2 | Var3 |
---|---|---|---|
x | 1 | 3 | 2 |
y | 2 | 5 | 7 |
df_wanted
id | Var1 | Var2 | Var3 | Var1-Var2 | Var1-Var3 | Var2-Var3 |
---|---|---|---|---|---|---|
x | 1 | 3 | 2 | -2 | -1 | 1 |
y | 2 | 5 | 7 | -3 | -5 | -2 |