[R] convert weekly time series data to monthly

2008-03-30 Thread Richard Saba

I have weekly time series data with year, month, day, and price variables.
The input data set for the weekly series takes the following form: 

 Year   month   day price
19908   20  119.1   
19908   27  124.5
19909   3   124.2
19909   10  125.2
19909   17  126.6
19909   24  127.2
199010  1   132.1
199010  8   133.3
199010  15  133.9
199010  22  134.5
199010  29  133.9
..  ... ... ...
... ... 
20083   3   313.7
20083   10  320
20083   17  325.7
20083   24  322.4 


I would like to collapse the data into monthly averages to merge with a
monthly series. The input data set for the monthly series takes the
following form: 

M-Y YearMonth   Change
Aug-199019908   -226.871
Sep-199019909   -896.333
Oct-1990199010  111.419
Nov-1990199011  -364.2
Dec-1990199012  -527.645
Jan-199119911   -70.935
Feb-199119912   231.214
Mar-199119913   -239 

... ... .   ..  


The merged data set should be of class(ts).
I can perform the conversions outside of R  and then import but I would
rather perform all conversions within R. I have looked through the zoo and
Rmetrics packages but without success. 

Any help will be appreciated.
Thanks,

Richard Saba
Department of Economics
Auburn University
Email:  [EMAIL PROTECTED]
Phone:  334 844-2922

__
R-help@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.


Re: [R] convert weekly time series data to monthly

2008-03-30 Thread Henrique Dallazuanna
If I understand:

x.new - cbind('M.Y'=paste(month.abb[x$month], x$Year, sep=-), x[-3])
aggregate(list(Change=x.new$price),
  list(M.Y=x.new[,M.Y], Year=x.new$Year,
Month=x.new$month),   FUN=mean)

On 30/03/2008, Richard Saba [EMAIL PROTECTED] wrote:

 I have weekly time series data with year, month, day, and price variables.
 The input data set for the weekly series takes the following form:

  Year month   day price
 1990  8   20  119.1   
 1990  8   27  124.5
 1990  9   3   124.2
 1990  9   10  125.2
 1990  9   17  126.6
 1990  9   24  127.2
 1990  10  1   132.1
 1990  10  8   133.3
 1990  10  15  133.9
 1990  10  22  134.5
 1990  10  29  133.9
 ..... ... ...
 ...   ... 
 2008  3   3   313.7
 2008  3   10  320
 2008  3   17  325.7
 2008  3   24  322.4


 I would like to collapse the data into monthly averages to merge with a
 monthly series. The input data set for the monthly series takes the
 following form:

 M-Y   YearMonth   Change
 Aug-1990  19908   -226.871
 Sep-1990  19909   -896.333
 Oct-1990  199010  111.419
 Nov-1990  199011  -364.2
 Dec-1990  199012  -527.645
 Jan-1991  19911   -70.935
 Feb-1991  19912   231.214
 Mar-1991  19913   -239

 ...   ... .   ..  


 The merged data set should be of class(ts).
 I can perform the conversions outside of R  and then import but I would
 rather perform all conversions within R. I have looked through the zoo and
 Rmetrics packages but without success.

 Any help will be appreciated.
 Thanks,

 Richard Saba
 Department of Economics
 Auburn University
 Email:  [EMAIL PROTECTED]
 Phone:  334 844-2922

 __
 R-help@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.



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

__
R-help@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.


Re: [R] convert weekly time series data to monthly

2008-03-30 Thread Gabor Grothendieck
Do you mean merge them into a two column series of price
for one column and change for another column?  That is what
I will assume since the result was not illustrated.

Suggest you read the help files and the three
vignettes in the zoo package.

Also R News 4/1 has info on dates.

If you were looking for OHLC representations then see
the xts package which in turn uses zoo and read its
documentation in addition to the above.


library(zoo) # ensure you are using zoo 1.5.0 or later
price.Lines - Year   month   day price
19908   20  119.1
19908   27  124.5
19909   3   124.2
19909   10  125.2
19909   17  126.6
19909   24  127.2
199010  1   132.1
199010  8   133.3
199010  15  133.9
199010  22  134.5
199010  29  133.9
20083   3   313.7
20083   10  320
20083   17  325.7
20083   24  322.4

price.DF - read.table(textConnection(price.Lines), header = TRUE)
price - with(price.DF,
zoo(price, as.Date(paste(Year, month, day, sep = -

change.Lines - M-Y YearMonth   Change
Aug-199019908   -226.871
Sep-199019909   -896.333
Oct-1990199010  111.419
Nov-1990199011  -364.2
Dec-1990199012  -527.645
Jan-199119911   -70.935
Feb-199119912   231.214
Mar-199119913   -239

change - read.zoo(textConnection(change.Lines), header = TRUE,
FUN = as.yearmon, format = %b-%Y,
colClasses = c(character, NULL, NULL, numeric))

# convert change series to Date using last of month as the date
time(change) - as.Date(time(change), frac = 1)

merge(price, change)


On Sun, Mar 30, 2008 at 11:24 AM, Richard Saba [EMAIL PROTECTED] wrote:

 I have weekly time series data with year, month, day, and price variables.
 The input data set for the weekly series takes the following form:

  Year   month   day price
 19908   20  119.1
 19908   27  124.5
 19909   3   124.2
 19909   10  125.2
 19909   17  126.6
 19909   24  127.2
 199010  1   132.1
 199010  8   133.3
 199010  15  133.9
 199010  22  134.5
 199010  29  133.9
 ..  ... ... ...
 ... ... 
 20083   3   313.7
 20083   10  320
 20083   17  325.7
 20083   24  322.4


 I would like to collapse the data into monthly averages to merge with a
 monthly series. The input data set for the monthly series takes the
 following form:

 M-Y YearMonth   Change
 Aug-199019908   -226.871
 Sep-199019909   -896.333
 Oct-1990199010  111.419
 Nov-1990199011  -364.2
 Dec-1990199012  -527.645
 Jan-199119911   -70.935
 Feb-199119912   231.214
 Mar-199119913   -239

 ... ... .   ..  


 The merged data set should be of class(ts).
 I can perform the conversions outside of R  and then import but I would
 rather perform all conversions within R. I have looked through the zoo and
 Rmetrics packages but without success.

 Any help will be appreciated.
 Thanks,

 Richard Saba
 Department of Economics
 Auburn University
 Email:  [EMAIL PROTECTED]
 Phone:  334 844-2922

 __
 R-help@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.


__
R-help@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.