XTS Subsetting question (noob)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

XTS Subsetting question (noob)

john.dempster78
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.

d = "2007-01-01"
P <- V['2007-01-01/']
Q <- V['d/']

Thanks,
J
Reply | Threaded
Open this post in threaded view
|

Re: XTS Subsetting question (noob)

Joshua Ulrich
On Tue, Oct 16, 2012 at 5:04 AM, john.dempster78
<[hidden email]> 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.
>
> ______________________________________________
> [hidden email] 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

______________________________________________
[hidden email] 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.