我想完全加入2 df.令我惊讶的是,dplyr的默认行为是加入NA,如果它们存在于两个df中.有没有阻止dplyr执行此操作的功能?
以下是内部联接的示例:
x <- data.frame(a = c(5, NA, 9), b = 1:3)
y <- data.frame(a = c(5, NA, 9), c = 4:6)
z <- dplyr::inner_join(x, y, by = 'a')
Run Code Online (Sandbox Code Playgroud)
我希望z只包含2条记录,而不是3.理想情况下,我希望这样做而不必事先用NA手动过滤掉记录,然后将它们附加到结果中(因为这看起来很笨拙).
aos*_*ith 19
你可以用na_matches = "never"
.这是针对v.7.0.0 的新闻,但我没有在文档中看到它.默认是na_matches = "na"
.
这将返回两行而不是三行:
dplyr::inner_join(x, y, by = 'a', na_matches = "never")
a b c
1 5 1 4
2 9 3 6
Run Code Online (Sandbox Code Playgroud)