Suppose I have the following two dataframes
dfA <- data.frame(x = rpois(10,2), y = rpois(10,2), z = rpois(10,2), q = rpois(10,2), t = rpois(10,2))
dfB <- data.frame(x = rpois(10,2), y = rpois(10,2), z = rpois(10,2), q = rpois(10,2), t = rpois(10,2))
dfAB <- map2_df(dfA, dfB, str_c, sep=",") %>%
rename_all(~ str_c('C', seq_along(.)))
dfC <- data.frame(x = rpois(10,2), y = rpois(10,2), z = rpois(10,2), q = rpois(10,2), t = rpois(10,2))
dfD <- data.frame(x = rpois(10,2), y = rpois(10,2), z = rpois(10,2), q = rpois(10,2), t = rpois(10,2))
dfCD <- map2_df(dfC, dfD, str_c, sep=",") %>%
rename_all(~ str_c('C', seq_along(.)))
What I looking for is to find the distance between coordinates in the first dataframe and the second, so I get a third dataframe with the distance between the first cell of dfAB and the first cell of dfCD, and the distance between the 2nd cell of dfAB and the 2nd cell of dfCD and so on; i.e. call columns C and rows R, I would like the distance between
dfAB and dfCD
C1 C2 C... C1 C2 C...
R1 R1 R1 R1
R2 R2 R2 R2
... ... ... ...
etc
What I am looking for is the distance between dfABC1R1 and dfCDC1R1, dfABC1R2 and dfCDC1R2, dfABC2R1 and dfCDC2R1, etc.
When I try using
dist(dfAB,dfCD)
I get the error: Error in dist(dfAB,dfCD) : invalid distance method
Any help is much appreciated