[R] XTS Subsetting question (noob)

Joshua Ulrich josh.m.ulrich at gmail.com
Tue Oct 16 13:55:36 CEST 2012


On Tue, Oct 16, 2012 at 5:04 AM, john.dempster78
<john.dempster78 at gmail.com> wrote:
> Hi,
> How can an xts object be subset using a date in a variable?
> E.g. in below, what is the right syntax for Q to get the same value as P?
> Obviously the syntax shown below doesnt work...
> V is an xts object.
>
> R

> P <- V['2007-01-01/']
> Q <- V['d/']
>
To clarify, d is a character string, not a Date.  In order for Q to be
like P, you need to create a character string from d that equals the
one you used to create P.  You can do this with paste().

Q <- V[paste(d,"/",sep="")]

> Thanks,
> J
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/XTS-Subsetting-question-noob-tp4646317.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.


--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com




More information about the R-help mailing list