[R-SIG-Finance] xts assignment via yearmon or string-based indexing

Jeff Ryan jeff.a.ryan at gmail.com
Mon Dec 1 04:13:40 CET 2008


Hi Brian,

Short answer is that it is expected behavior, at least given that no
[<-.xts method exists. :)

Is this desired behavior?? Not really.  I will look to make this more
consistent with the [.xts method.

Thanks for the report.

For now a clunky looking workaround can be had with:

> series[index(series) %in% timeBasedSeq('185805/185807')] <- TRUE
> head(series)
          [,1]
Jan 1858 FALSE
Feb 1858 FALSE
Mar 1858 FALSE
Apr 1858 FALSE
May 1858  TRUE
Jun 1858  TRUE

Thanks,
Jeff


On Sun, Nov 30, 2008 at 5: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.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list