Dear all
How to test if xts date exists ? is.null doesn't work.
SPY["2009-01-18"] doesn't exist but I can't catch it in my
script.
library(quantmod)
getSymbols("SPY")
> SPY["2009-01-16"]
SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
2009-01-16 85.86 85.99 83.05 85.06 399237200 76.58
> SPY["2009-01-18"]
SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
> is.null(SPY["2009-01-18"])
[1] FALSE
!length(SPY["2009-01-18"])
#[1] TRUE
? !length(SPY["2009-01-16"])
#[1] FALSE
#or
?!nrow(SPY["2009-01-16"])
A.K.
On Saturday, January 25, 2014 10:27 AM, ce <zadig_1 at excite.com> wrote:
Dear all
How to test if xts date exists ? is.null doesn't work.?
SPY["2009-01-18"] doesn't exist but I can't catch it in my
script.
library(quantmod)
getSymbols("SPY")
> SPY["2009-01-16"]
? ? ? ? ? SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
2009-01-16? ? 85.86? ? 85.99? 83.05? ? 85.06? 399237200? ? ? ? 76.58
> SPY["2009-01-18"]
? ? SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
> is.null(SPY["2009-01-18"])
[1] FALSE
______________________________________________
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.
You can use the which.i argument to [.xts:> is.null(SPY["2009-01-18",which.i=TRUE])[1] TRUE Best, -- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com On Sat, Jan 25, 2014 at 9:27 AM, ce <zadig_1@excite.com> wrote:> Dear all > > > How to test if xts date exists ? is.null doesn't work. SPY["2009-01-18"] > doesn't exist but I can't catch it in my script. > > library(quantmod) > > getSymbols("SPY") > > > SPY["2009-01-16"] > SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted > 2009-01-16 85.86 85.99 83.05 85.06 399237200 76.58 > > > > > SPY["2009-01-18"] > SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted > > > > is.null(SPY["2009-01-18"]) > [1] FALSE > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]