Say I have the following two data-frames and I want to merge them using merge
function.
> x <- data.frame(id=c("a", "b", "c"), type=c("good", "ok", "not-ok"))
> y <- data.frame(id=c("b", "d"), type=c("ok", "good"), kind=c("A", "B"))
> merge(x, y, by.x="id", by.y="id", all=TRUE)
id type.x type.y kind
1 a good <NA> <NA>
2 b ok ok A
3 c not-ok <NA> <NA>
4 d <NA> good B
What I want to get is
id type kind
1 a good <NA>
2 b ok A
3 c not-ok <NA>
4 d good B
Is there a nice way to do this in R, please? Thanks.