I have a dataframe of letters and dates:
Dates <- data.frame(X = c("A", "B", "C", "D"), Y = c("1/1/1988","1/1/2000","11/1/1996", "2/1/1990"))
Dates$Y <- as.Date(Dates$Y, "%m/%d/%Y")
I'm trying to turn this data frame into a symmetrical matrix where the values in the matrix are the absolute difference (in years) between the dates of all the possible combinations of letters. So the output would look like this:
Output <- matrix(c(0, 12.01, 8.84, 12.01, 0, 3.17, 8.84, 3.17, 0), nrow=3, ncol=3,
dimnames = list(c("A", "B", "C"),
c("A", "B", "C")))
Thank you so much in advance!