I would like to merge two data frames (df1 and df2). The script below works well for the letters. But, when I added a df with "-", it doesn't work anymore. I tried to add the "-" as "" in the df1, but that failed, too.
I would like the script to skip or leave a blank when it meets "-".
To note: I would need to know where the blanks are so I wouldn't like to remove the blanks from a data frame.
Any input highly appreciated!
df1 <- data.frame(scale = c(0.62, 0.29, -0.9, -0.74, 1.19, 0.48, -0.4, 1.38, -1.5, 1.06, 0.64, -0.78, 0.12, -0.85, -2.53, -0.18, -0.05, 1.08, 0.81, 0.26,""),
aa = c('A','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','V','W','Y','-'))
df2 <- df(col1 = c('-', '-' ,'E', 'S', 'P', 'V', 'F', 'A', 'F', 'P', 'K', 'A', 'L', 'D', 'L', 'E', 'T' ,'H', 'I', 'E', 'K' ,'L', 'F', 'L', 'Y'),
col2 = c('D','D','T','L','D','D','S','D','E','D','D','I','V','V','E','S','Q','D','P','P','L','-','S','W','-'))
matched_res_all <- df2 %>%
left_join(df1, by = c(col1 = "aa")) %>%
left_join(df1, by = c(col2 = "aa"))
view(matched_res_all)