Calculate all the absolute differences between 6 columns of a table using mutate? [duplicate]
问题 This question already has answers here : Pairwise subtraction in a dataframe R (2 answers) Closed 7 months ago . I have a table with 6 columns Z1 to Z6, and I want to calculate the absolute value of the difference between each of these columns. So far, I enumerate all the differences in a mutate command: FactArray <- FactArray %>% mutate(diff12 = abs(Z1-Z2), diff13 = abs(Z1-Z3), diff14 = abs(Z1-Z4), diff15 = abs(Z1-Z5), diff16 = abs(Z1-Z6), diff23 = abs(Z2-Z3), diff24 = abs(Z2-Z4), diff25 =