apple = data.frame(Obs = c(1:4), Color = c("red", "red", "red", "green"), Weight = c(1.1, 1.2, 1.3, 1.4))
orange = data.frame(Obs = c(1:6), Weight = c(2, 3, 4, 5, 6, 7))
I have two data.frames, apple
and orange
, in which the latter's columns are a subset of the former's.
> apple
Obs Color Weight
1 1 red 1.1
2 2 red 1.2
3 3 red 1.3
4 4 green 1.4
> orange
Obs Weight
1 1 2
2 2 3
3 3 4
4 4 5
5 5 6
6 6 7
I would like to merge the 2 data.frames and the result should look something like this:
> apple_orange
Obs Color Weight
1 1 red 1.1
2 2 red 1.2
3 3 red 1.3
4 4 green 1.4
5 1 NA 2
6 2 NA 3
7 3 NA 4
8 4 NA 5
9 5 NA 6
10 6 NA 7
What's a way to merge this so that I do not have the specify the specific column names? I.e. my actual dataset has hundreds of columns in common, so I'd rather not type them out one by one.