[R-SIG-Finance] Using rownames to index into xts objects
Jeff Ryan
jeff.a.ryan at gmail.com
Wed Feb 27 16:51:01 CET 2008
Hi Murali:
Try:
> xts.ts[which(rownames(xts.ts) %in% rownames(yts.ts))]
The problem is that the first '2007-02-10' is getting interpreted as a
'date' index, if you will, and discarding the rest:
The way that gets interpreted is in the following form (with the range
below for illustrative purposes)
.
xts.ts['2007-02-10::2007-02-20']
Jeff
On Wed, Feb 27, 2008 at 9:37 AM, Murali Menon <feanor0 at hotmail.com> wrote:
>
> Hi,
>
> Another index-related query on xts. If I have two xts objects indexed by different dates, and I want to extract the common dates to reindex into these objects (to find contemporaneous values), I thought the following would work:
>
> > xx <- matrix(rnorm(1000), ncol=10); xts.ts <- xts(xx, as.Date(13514:13613), origin="1970-01-01")
> > yy <- matrix(rnorm(1000), ncol=10); yts.ts <- xts(yy, as.Date(13554:13653), origin="1970-01-01")
> > intersect(rownames(xts.ts),rownames(yts.ts)) [1] "2007-02-10" "2007-02-11" "2007-02-12" "2007-02-13" "2007-02-14" "2007-02-15" "2007-02-16" "2007-02-17" "2007-02-18" "2007-02-19" "2007-02-20"[12] "2007-02-21" "2007-02-22" "2007-02-23" "2007-02-24" "2007-02-25" "2007-02-26" "2007-02-27" "2007-02-28" "2007-03-01" "2007-03-02" "2007-03-03"[23] "2007-03-04" "2007-03-05" "2007-03-06" "2007-03-07" "2007-03-08" "2007-03-09" "2007-03-10" "2007-03-11" "2007-03-12" "2007-03-13" "2007-03-14"[34] "2007-03-15" "2007-03-16" "2007-03-17" "2007-03-18" "2007-03-19" "2007-03-20" "2007-03-21" "2007-03-22" "2007-03-23" "2007-03-24" "2007-03-25"[45] "2007-03-26" "2007-03-27" "2007-03-28" "2007-03-29" "2007-03-30" "2007-03-31" "2007-04-01" "2007-04-02" "2007-04-03" "2007-04-04" "2007-04-05"[56] "2007-04-06" "2007-04-07" "2007-04-08" "2007-04-09" "2007-04-10"
>
> so we have 60 common dates between the two series. I now want to fish out just those entries:
>
> > xts.ts[intersect(rownames(xts.ts), rownames(yts.ts)),]2007-02-10 -1.319601 -0.09154885 -1.991032 0.9530218 -0.3577950 -0.02353374 -0.4677263 -1.072972 -1.881379 1.130009
>
> It only returns the first entry. I guess I'm missing some trivial matter here, but can't for the life of me figure out what. Please help!
>
> Cheers,
> Murali
> _________________________________________________________________
> Climb to the top of the charts! Play the word scramble challenge with star power.
>
> [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>
--
There's a way to do it better - find it.
Thomas A. Edison
More information about the R-SIG-Finance
mailing list