Skip to content
Prev 140672 / 398506 Next

convert weekly time series data to monthly

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
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
"
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             Year    Month   Change
Aug-1990        1990    8       -226.871
Sep-1990        1990    9       -896.333
Oct-1990        1990    10      111.419
Nov-1990        1990    11      -364.2
Dec-1990        1990    12      -527.645
Jan-1991        1991    1       -70.935
Feb-1991        1991    2       231.214
Mar-1991        1991    3       -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 <sabaric at auburn.edu> wrote: