I have 5 temporal matrices.
Each has a different number of rows and columns, but each has a first column called Year
. Each start and end in a different year
, so there is no common starting or ending date among all the matrices.
I want to combine all of the matrices into one based on the year those data were collected (i.e., the data collected in one matrix in a particular year, correspond to the data in other matrices for that same year).
For those matrices that do not have a corresponding year, I want to fill those blanks with NA
. The data will not line up according to year just by using
Reduce(function(x,y) merge(x,y,1,all=T),list(matrix1, matrix2,...))
How can I line the data up and combine them into one matrix?
Matrix1:
Year 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1969 0 5 5 3 3 0 3 1 1 0 2 0 0 1 1 0 0
1970 5 10 5 4 8 5 2 2 2 1 0 2 0 0 1 0 0
1971 0 10 3 5 2 1 2 1 1 0 0 0 0 0 0 0 0
1972 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
...
2014
Matrix2:
Year Checked
1969 1995
1970 2017
1971 1996
1972 1972
1973 2010
1974 2008
...
2015
Matrix3:
Year WOak
1983 1.43
1984 1.08
1985 2.01
1986 1.32
1987 1.16
1988 3.16
...
2016
Matrix 4:
Year C_Registered M_Registered P_Registered T_Registered
1969 NA NA NA 55
1970 NA NA NA 72
1971 NA NA NA 44
1972 NA NA NA 0
1973 NA NA NA 48
1974 NA NA NA 59
1975 NA NA NA 2
...
2015
Matrix5:
Year Hunters Trips Harvest TripsPerHunter
1949 NA NA 873 NA
1950 NA NA NA NA
1951 NA 11298 927 NA
1952 NA 19620 1047 NA
1953 NA 18040 1100 NA
1954 NA 15073 1200 NA
1955 NA 33373 4458 NA
...
2015