I was wondering is there a way to automate (e.g., loop) the subtraction of (X2-X1
), (X3-X1
), (X3-X2
) in my data
below and add them as three new columns to the data
?
m="
id X1 X2 X3
A 1 0 4
B 2 2 2
C 3 4 1"
data <- read.table(text = m, h = T)