General R Recommendations: DO NOT USE cbind WHEN IT IS REQUIRED:
A <- data.frame(X1=c('R1','R1','R2','R4','R4','R4'),X2=c(5.1,4.8,4.9,5.0,5.0,5.3)) B <- data.frame(X1=c('R1','R2','R3','R4'),X2=c(5,4.9,5.2,5.1))
(You did factors of these numbers, and you cannot apply arithmetic operators to factors.)
If there are unique matches, the merge function returns all possible pairs:
merge(A,B, by=1) merge(A,B, by=1)[,2] - merge(A,B, by=1)[,3]
source share