0

I have various matrices, each representing a country. The matrices are composed of two columns: one has the GDP value and the other has the year on which the GDP was measured.

I want to create a data frame with the first column containing the year and the other columns containing the GDP measurements of each country.

My problem: not all the countries have the same number of observations. USA, for example, has data back to 1960, while Russia has data only since 1995.

> United.States
    TIME    Value
6936 1960-Q1 2.705815
6937 1960-Q2 2.705560
6938 1960-Q3 2.705727
6939 1960-Q4 2.704912
6940 1961-Q1 2.705366
6941 1961-Q2 2.706595
6942 1961-Q3 2.707699
6943 1961-Q4 2.709036
6944 1962-Q1 2.710225...


> Russia
    TIME    Value
6244 1995-Q1 2.662320
6245 1995-Q2 2.662886
6246 1995-Q3 2.663187
6247 1995-Q4 2.661674
6248 1996-Q1 2.660746...

Can I connect these two matrices in a way that the USA and Russia of, say, 1995-Q3 are in the same row?

D Pinto
  • 871
  • 9
  • 27

1 Answers1

2
merge(United.States, Russia, by.x = "TIME", by.y = "TIME", all = TRUE)
D Pinto
  • 871
  • 9
  • 27