[R] Difficulties in starting up with its package
Gabor Grothendieck
ggrothendieck at myway.com
Thu Aug 26 07:28:17 CEST 2004
Ajay Shah <ajayshah <at> mayin.org> writes:
:
: Folks,
:
: I'm trying to learn `its' and am stuck on many basics.
Not sure about those issues but I am familiar with zoo and you could do
the above in zoo like this.
require(zoo)
d <- seq(as.Date("2000-01-01"), as.Date("2000-01-10"), by = "day")
x1 <- zoo(matrix(1:30,ncol=3), d)
dw <- d[as.numeric(format(d,"%w")) %in% 1:5]
x2 <- zoo(matrix(1:30,ncol=3), dw)
print(x2)
str(x1)
str(x2)
write.table(data.frame(time = time(x1), unclass(x1)), file = "/mytest.txt")
y <- read.table("/mytest.txt", header = T, as.is = T)
y <- zoo(data.matrix(y[,-1]),as.Date(y[,1]))
print(y)
print(x1)
# this works since y and x1 same times and are conformable but in general
# you need to do a merge first to align them
y-x1
nifty.its <-
structure(c(1.01494311428086, 1.00936924878702, 1.01265263274214,
0.984531863814928, 0.980409543074067, 0.98469241317728, 1.01059040709914,
1.03118189975644, 0.998663641731672, 0.995083089562457, 0.992244183137353,
0.951052697932426, 0.983330571665286), .Dim = as.integer(c(13,
1)), .Dimnames = list(c("2004-05-04", "2004-05-05", "2004-05-06",
"2004-05-07", "2004-05-10", "2004-05-20", "2004-05-21", "2004-05-24",
"2004-05-25", "2004-05-26", "2004-05-27", "2004-05-28", "2004-05-31"),
"r.nifty"))
inrusd.its <-
structure(c(1.01311623699683, 0.996651785714286, 0.997088465845465,
1, 1.00651392632525, 1.00937290783307, 0.999115631218218, 0.997565833148927,
1.00421472937001, 1.00397614314115, 0.998899889989, 0.995594713656388,
0.995353982300885, 1.00466770393421, 0.99933628318584, 1, 1.00154970112907,
1.00221043324492, 0.998456109395677), .Dim = as.integer(c(19,
1)), .Dimnames = list(c("2004-05-03", "2004-05-05", "2004-05-06",
"2004-05-07", "2004-05-10", "2004-05-11", "2004-05-12", "2004-05-13",
"2004-05-14", "2004-05-17", "2004-05-18", "2004-05-19", "2004-05-20",
"2004-05-21", "2004-05-24", "2004-05-25", "2004-05-26", "2004-05-27",
"2004-05-28"), "r.inrusd"))
nifty.zoo <- zoo(nifty.its, as.Date(rownames(nifty.its)))
rownames(nifty.zoo) <- NULL
inrusd.zoo <- zoo(inrusd.its, as.Date(rownames(inrusd.its)))
rownames(inrusd.zoo) <- NULL
# merge.zoo is similar to union in its
merge(nifty.zoo, inrusd.zoo)
# merge.zoo with all = FALSE is similar to intersect in its
merge(nifty.zoo, inrusd.zoo, all = FALSE)
More information about the R-help
mailing list