I'm using R and need merge data with different lenghts
Following this dataset
> means2012
# A tibble: 232 x 2
exporter eci
<fct> <dbl>
1 ABW 0.235
2 AFG -0.850
3 AGO -1.40
4 AIA 1.34
5 ALB -0.480
6 AND 1.22
7 ANS 0.662
8 ARE 0.289
9 ARG 0.176
10 ARM 0.490
# ... with 222 more rows
> means2013
# A tibble: 234 x 2
exporter eci
<fct> <dbl>
1 ABW 0.534
2 AFG -0.834
3 AGO -1.26
4 AIA 1.47
5 ALB -0.498
6 AND 1.13
7 ANS 0.616
8 ARE 0.267
9 ARG 0.127
10 ARM 0.0616
# ... with 224 more rows
> str(means2012)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 232 obs. of 2 variables:
$ exporter: Factor w/ 242 levels "ABW","AFG","AGO",..: 1 2 3 4 5 6 7 9 10 11 ...
$ eci : num 0.235 -0.85 -1.404 1.337 -0.48 ...
> str(means2013)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 234 obs. of 2 variables:
$ exporter: Factor w/ 242 levels "ABW","AFG","AGO",..: 1 2 3 4 5 6 7 9 10 11 ...
$ eci : num 0.534 -0.834 -1.263 1.471 -0.498 ...
Note that 2 tibble has different lenghts. "Exporter" are countries.
Is there any way to merge both tibble, looking to the factors (Exporter) and fill the missing it with "na"?
It doesn't matter if is a tibble, dataframe, or other kind.
like this:
tibble 1
a 5
b 10
c 15
d 25
tibble 2
a 7
c 23
d 20
merged one:
a 5 7
b 10 na
c 15 23
d 25 20