I'm new to r. This is my first forum question... I'm trying to merge two datasets like these:
df1 <- data.frame(ID = letters[1:5],
x = 5:9,
y = c(NA,6,5,NA,NA))
> df1
ID x y
1 a 5 NA
2 b 6 6
3 c 7 5
4 d 8 NA
5 e 9 NA
df2 <- data.frame(ID = letters[4:8],
y = 7:11,
z = c(4,3,NA,2,1))
> df2
ID y z
1 d 7 4
2 e 8 3
3 f 9 NA
4 g 10 2
5 h 11 1
outcome should look like this:
> df3
ID x y z
1 a 5 NA NA
2 b 6 6 NA
3 c 7 5 NA
4 d 8 7 4
5 e 9 8 3
6 f NA 9 NA
7 g NA 10 2
8 h NA 11 1
I looked around in various forums but couldn't find the solution to this specific problem :/
Any suggestions are much appreciated!