I would like to create multiple variables to show the time differences from a variable (V0) for several variables. I would like the absolute difference (i.e., ignoring the sign of the difference). All my variables are in date format.
I have the below code, which works, but I imagine there is a neater/better way of doing this in fewer lines of code. I've tried a couple of things without much luck.
df$V1_timediff <- (abs(as.numeric(difftime(df$V0, df$V1, units = "days"))))
df$V2_timediff <- (abs(as.numeric(difftime(df$V0, df$V2, units = "days"))))
df$V3_timediff <- (abs(as.numeric(difftime(df$V0, df$V3, units = "days"))))
df$V4_timediff <- (abs(as.numeric(difftime(df$V0, df$V4, units = "days"))))