R Version 2.11.1 32-bit on Windows 7
I got two data sets: data_A and data_B:
USER_A USER_B ACTION
1 11 0.3
1 13 0.
I wrote the package safejoin which solves this very succintly :
# devtools::install_github("moodymudskipper/safejoin")
library(safejoin)
safe_left_join(data_A,data_B, by = c("USER_A", "USER_B"),
conflict = ~ .x+ ifelse(is.na(.y),0,.y))
# USER_A USER_B ACTION
# 1 1 11 0.30
# 2 1 13 0.42
# 3 1 16 0.63
# 4 1 17 0.26
# 5 2 11 0.39
# 6 2 14 0.28
In case of conflict, the function fed to the conflict argument will be used
on pairs of conflicting columns