[R-SIG-Finance] xts assignment via yearmon or string-based indexing
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Dec 1 03:07:06 CET 2008
Don't know what is wrong but as a workaround note that since xts is a
subclass of zoo you can also use zoo methods on xts objects.
See ?window.zoo
y1 <- as.yearmon("1858-05")
y2 <- as.yearmon("1858-07")
window(series, start = y1, end = y2) <- TRUE
On Sun, Nov 30, 2008 at 6:06 PM, Brian Lee Yung Rowe <brian at muxspace.com> wrote:
> Hi,
>
> I have an xts series and want to update some of the values in the series.
> This works fine when I use an integer index (or list of integer indices),
> but it doesn't work if I use other methods like the string-based indexing or
> a list of yearmons. Is this the expected behavior or am I doing something
> wrong?
>
> Brian
>
>
>> dates <- timeBasedSeq('185801/2002')
>> series <- xts(rep(F, length(dates)), dates)
>
>> series['1858-05::1858-07'] <- T
>> head(series)
> [,1]
> Jan 1858 FALSE
> Feb 1858 FALSE
> Mar 1858 FALSE
> Apr 1858 FALSE
> May 1858 FALSE # Expected to be T
> Jun 1858 FALSE # Expected to be T
>
>> series[dates.1] <- T
>> series[dates.1]
> [,1]
> May 1858 FALSE # Expected to be T
> Jun 1858 FALSE # Expected to be T
> Jul 1858 FALSE # Expected to be T
>
>> series[1] <- T
>> head(series)
> [,1]
> Jan 1858 TRUE # T as expected
> Feb 1858 FALSE
> Mar 1858 FALSE
> Apr 1858 FALSE
> May 1858 FALSE
> Jun 1858 FALSE
>
>> series[c(2,3)] <- T
>> head(series)
> [,1]
> Jan 1858 TRUE
> Feb 1858 TRUE # This worked as expected
> Mar 1858 TRUE # This worked as expected
> Apr 1858 FALSE
> May 1858 FALSE
> Jun 1858 FALSE
>
>
>
> _______________________________________________
> 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.
>
More information about the R-SIG-Finance
mailing list