[R] Merging two data files based on common dates

Sarah Goslee sarah.goslee at gmail.com
Tue Jan 5 16:51:18 CET 2016


Since the date columns have different names, you need to specify the
by.x and by.y arguments to merge().

Other than that, it should work.

If you need more help, please use dput() to provide some of your data,
and include both the code you used and the error message or incorrect
result you got (that is, a reproducible example). And also, post this
information in plain text rather than HTML.

Sarah

On Tue, Jan 5, 2016 at 1:19 AM,  <Santosh.Aryal at csiro.au> wrote:
> Hello there
> Pardon my ignorance but, I have two data files with different series of dates and x and y values.
> There are common dates in both files. For example
>>datafile1
> date1                     xval
> 31/12/1982         20
> 1/01/1983            30
> 2/01/1983            40
> 3/01/1983            50
> 4/01/1983            60
> 5/01/1983          70
> ...
> 01/01/2010       77
> ...
> 31/12/1012       99
>
>>datafile2
> date2                  yval
> 3/01/1983            0.4
> 4/01/1983            0.5
> 5/01/1983            0.6
> ..
> 01/01/2010        88
>
> All I want is a file/object that merges the two files with data for common dates to look like this.
> date                    yval  xval
> 3/01/1983            0.4  50
> 4/01/1983            0.5  60
> 5/01/1983            0.6  70
> ..
> 01/01/2010        88     77
>
> I tried ' merge' and ' join' commands but somehow I have not been able to get that. Any help will be appreciated.
> Thank you.
>
>
> Best regards
>
> Santosh Aryal
> CSIRO Land and Water
> GPO Box 1666, Canberra ACT 2601
> Ph:   02 6246 5963
> Email: santosh.aryal at csiro.au<mailto:santosh.aryal at csiro.au>
>
>
>

-- 
Sarah Goslee
http://www.numberwright.com



More information about the R-help mailing list