I have two files (file1.csv and file2.csv). As shown below, file1 contains two columns date and variable x1 that has 365 observations (whole year). file 2 contains column date as file1 and many other variables. I'm interested only in variable x45 that has 24 observations only (2 observations each month).
file1
date x1
1/01/2005 33
2/01/2005 24
3/01/2005 72
31/12/2005 52
file 2
date x2 x3 x45
1/01/2005 115
5/02/2005 125
13/04/2005 127
31/12/2005 138
so I'd like to add column x45 to file1.csv to look like
date x1 x45
1/01/2005 33 115
2/01/2005 24 NA
3/01/2005 72 NA
31/12/2005 52 138
I have tried using
file1= read.csv("D:/file1.csv")
file2= read.csv("D:/file2.csv")
file3 = merge(file1, file2)
However, file 3 has only 24 rows (observations) and omits the rest of observations in file 1.
Any help to get the result as described above would be much appreciated.