[R] Merging daily and weekly data

Edwin Sendjaja edwin7 at gmx.net
Mon Apr 14 13:59:48 CEST 2008


Hi Oystein,


Maybe this is what you are looking for:


Keyword: merge()
----------------------------------------------------------------------
table1<-read.table("daily.data")
table2<-read.table("weekly.data")


(maybe you need to create a new common coloumn for daily and weekly data set.   
For example: year_week)

data<-merge(table1, table2, by.x="year_week", by.y="year_week")  


data




I hope it helps,

Edwin Sendjaja

Am Montag, 14. April 2008 11:09:12 schrieb Øystein Myrland:
> Dear R-help group,
>
> I have a dataset with daily closing prices from a stock exchange
> (consecutive 5 trading days) from a firm trading a specific commodity. The
> date variable looks like:
>
> quote_date
> 20080411
>
> With the format; yyyymmdd.
>
> Moreover, I have another data set with a (average) weekly price of the
> underlying commodity. The date variables in this dataset are only year and
> a week number.
>
> I would like to calculate a common date number or ID based on week number
> that enables me to merge these two datasets, so that it looks like this:
>
> quote_date	year	week	week.price
> 20080407	2008	15	27.45
> 20080408	2008	15	27.45
> 20080409	2008	15	27.45
> 20080410	2008	15	27.45
> 20080411	2008	15	27.45
>
> The weekly price is constant for the 5 trading days in the daily file. Any
> good suggestions on how to do this?
>
> All the best,
> Oystein
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented, minimal,
> self-contained, reproducible code.



More information about the R-help mailing list