Skip to content
Prev 316734 / 398506 Next

Split xts data set into weeks

Hi, Jeff

Thank you for your advice.
I tried to make a piece of reproducible codes.
Would you please paste the following codes to R console and make a confirmation?

#Codes start from here

library("quantmod")
tmp<-structure(c(112.34, 112.89, 112.75, 113.5, 115.16, 115.21, 114.84,
114.93, 115.05, 114.46, 113.34, 113.71, 113.56, 115.08, 115.97,
115.26, 115.22, 115.24, 115.24, 114.98, 111.96, 112.75, 112.5,
113.1, 114.85, 114.55, 114.55, 114.75, 114.2, 112.92, 112.87,
112.8, 113.54, 115.05, 115.06, 114.85, 114.93, 115.09, 114.28,
113.92), class = c("xts", "zoo"), .indexCLASS = "Date", tclass =
"Date", .indexTZ = "", tzone = "", index = structure(c(1298818800,
1298905200, 1298991600, 1299078000, 1299164400, 1299423600, 1299510000,
1299596400, 1299682800, 1299769200), tzone = "", tclass = "Date"),
.Dim = c(10L,
4L), .Dimnames = list(NULL, c("Open", "High", "Low", "Close")))
class(tmp)
(res1<-split(tmp,f="weeks"))
(res2<-split(tmp,frequency="weeks"))

#Codes end here

the original data is saved in "tmp" and the split() results are saved
in res1 and res2.
res1 is the result of "f" and res2 is the resut of "frequency", both break the
week started from "2011-02-28" .... and result of "frequency" is even worse.

BTW, my R version is as following:
platform       i686-pc-linux-gnu
arch           i686
os             linux-gnu
system         i686, linux-gnu
status
major          2
minor          15.2
year           2012
month          10
day            26
svn rev        61015
language       R
version.string R version 2.15.2 (2012-10-26)
nickname       Trick or Treat

Thank you.

Seimizu Joukan