<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.16.1">
</HEAD>
<BODY>
<FONT COLOR="#000000">Surprisingly, that doesn't work. What is particularly strange is that the indexing yields (to me) unexpected results. Do you know if this is expected behavior? Please bear with the code below; the pay off is at the end (if you consider strange behavior a payoff).</FONT><BR>
<BR>
<FONT COLOR="#000000">> class(index(series))</FONT><BR>
<FONT COLOR="#000000">[1] "yearmon"</FONT><BR>
<FONT COLOR="#000000">> head(series) # Initial state</FONT><BR>
<FONT COLOR="#000000"> [,1]</FONT><BR>
<FONT COLOR="#000000">Jan 1857 FALSE</FONT><BR>
<FONT COLOR="#000000">Feb 1857 FALSE</FONT><BR>
<FONT COLOR="#000000">Mar 1857 FALSE</FONT><BR>
<FONT COLOR="#000000">Apr 1857 FALSE</FONT><BR>
<FONT COLOR="#000000">May 1857 FALSE</FONT><BR>
<FONT COLOR="#000000">Jun 1857 FALSE</FONT><BR>
<FONT COLOR="#000000">> tail(series)</FONT><BR>
<FONT COLOR="#000000"> [,1]</FONT><BR>
<FONT COLOR="#000000">Jul 2001 FALSE</FONT><BR>
<FONT COLOR="#000000">Aug 2001 FALSE</FONT><BR>
<FONT COLOR="#000000">Sep 2001 FALSE</FONT><BR>
<FONT COLOR="#000000">Oct 2001 FALSE</FONT><BR>
<FONT COLOR="#000000">Nov 2001 FALSE</FONT><BR>
<FONT COLOR="#000000">Dec 2001 FALSE</FONT><BR>
<BR>
<FONT COLOR="#000000">> y1 <- as.yearmon("1858-05") </FONT><BR>
<FONT COLOR="#000000">> y2 <- as.yearmon("1858-07") </FONT><BR>
<FONT COLOR="#000000">> window(series, start = y1, end = y2) <- TRUE</FONT><BR>
<FONT COLOR="#000000">> </FONT><BR>
<FONT COLOR="#000000">> head(series)</FONT><BR>
<FONT COLOR="#000000"> [,1]</FONT><BR>
<FONT COLOR="#000000">Jan 1857 FALSE</FONT><BR>
<FONT COLOR="#000000">Feb 1857 FALSE</FONT><BR>
<FONT COLOR="#000000">Mar 1857 FALSE</FONT><BR>
<FONT COLOR="#000000">Apr 1857 FALSE</FONT><BR>
<FONT COLOR="#000000">May 1857 FALSE # Expected T</FONT><BR>
<FONT COLOR="#000000">Jun 1857 FALSE # Expected T</FONT><BR>
<BR>
<FONT COLOR="#000000">> # This is the strange part</FONT><BR>
<FONT COLOR="#000000">> head(window(series, start=y1))</FONT><BR>
<FONT COLOR="#000000"> [,1]</FONT><BR>
<FONT COLOR="#000000">Feb 1970 FALSE # But y1 == as.yearmon("1858-05")</FONT><BR>
<FONT COLOR="#000000">Mar 1970 FALSE</FONT><BR>
<FONT COLOR="#000000">Apr 1970 FALSE</FONT><BR>
<FONT COLOR="#000000">May 1970 FALSE</FONT><BR>
<FONT COLOR="#000000">Jun 1970 FALSE</FONT><BR>
<FONT COLOR="#000000">Jul 1970 FALSE</FONT><BR>
<BR>
<FONT COLOR="#000000">> head(window(series, start=y1, end=c(2001,12))) # No data returned?</FONT><BR>
<FONT COLOR="#000000">Data:</FONT><BR>
<FONT COLOR="#000000">numeric(0)</FONT><BR>
<BR>
<FONT COLOR="#000000">Index:</FONT><BR>
<FONT COLOR="#000000">integer(0)</FONT><BR>
<FONT COLOR="#000000">> head(window(series, start=y1, end=as.yearmon('2001-12'))) # Same thing using yearmon?</FONT><BR>
<FONT COLOR="#000000">Data:</FONT><BR>
<FONT COLOR="#000000">numeric(0)</FONT><BR>
<BR>
<FONT COLOR="#000000">Index:</FONT><BR>
<FONT COLOR="#000000">integer(0)</FONT><BR>
<BR>
<FONT COLOR="#000000">> # Let's try y2 just for fun</FONT><BR>
<FONT COLOR="#000000">> y2</FONT><BR>
<FONT COLOR="#000000">[1] "Jul 1858"</FONT><BR>
<FONT COLOR="#000000">> head(window(series, start=y2))</FONT><BR>
<FONT COLOR="#000000"> [,1]</FONT><BR>
<FONT COLOR="#000000">Feb 1970 FALSE # ???</FONT><BR>
<FONT COLOR="#000000">Mar 1970 FALSE</FONT><BR>
<FONT COLOR="#000000">Apr 1970 FALSE</FONT><BR>
<FONT COLOR="#000000">May 1970 FALSE</FONT><BR>
<FONT COLOR="#000000">Jun 1970 FALSE</FONT><BR>
<FONT COLOR="#000000">Jul 1970 FALSE</FONT><BR>
<BR>
<BR>
<FONT COLOR="#000000">It seems that the values of the yearmons are being interpreted incorrectly. Any ideas on why this is happening and what is to be done about it?</FONT><BR>
<BR>
<FONT COLOR="#000000">Thanks,</FONT><BR>
<FONT COLOR="#000000">Brian</FONT><BR>
<BR>
----- Original message ----- <BR>
Sent: 2008/11/30 21:07:06 <BR>
Subject: Re:Re: [R-SIG-Finance] xts assignment via yearmon or string-based indexing <BR>
<BR>
Don't know what is wrong but as a workaround note that since xts is a <BR>
subclass of zoo you can also use zoo methods on xts objects. <BR>
See ?window.zoo <BR>
<BR>
y1 <- as.yearmon("1858-05") <BR>
y2 <- as.yearmon("1858-07") <BR>
window(series, start = y1, end = y2) <- TRUE <BR>
<BR>
<BR>
<BR>
On Sun, Nov 30, 2008 at 6:06 PM, Brian Lee Yung Rowe wrote: <BR>
> Hi, <BR>
> <BR>
> I have an xts series and want to update some of the values in the series. <BR>
> This works fine when I use an integer index (or list of integer indices), <BR>
> but it doesn't work if I use other methods like the string-based indexing or <BR>
> a list of yearmons. Is this the expected behavior or am I doing something <BR>
> wrong? <BR>
> <BR>
> Brian <BR>
> <BR>
> <BR>
>> dates <- timeBasedSeq('185801/2002') <BR>
>> series <- xts(rep(F, length(dates)), dates) <BR>
> <BR>
>> series['1858-05::1858-07'] <- T <BR>
>> head(series) <BR>
> [,1] <BR>
> Jan 1858 FALSE <BR>
> Feb 1858 FALSE <BR>
> Mar 1858 FALSE <BR>
> Apr 1858 FALSE <BR>
> May 1858 FALSE # Expected to be T <BR>
> Jun 1858 FALSE # Expected to be T <BR>
> <BR>
>> series[dates.1] <- T <BR>
>> series[dates.1] <BR>
> [,1] <BR>
> May 1858 FALSE # Expected to be T <BR>
> Jun 1858 FALSE # Expected to be T <BR>
> Jul 1858 FALSE # Expected to be T <BR>
> <BR>
>> series[1] <- T <BR>
>> head(series) <BR>
> [,1] <BR>
> Jan 1858 TRUE # T as expected <BR>
> Feb 1858 FALSE <BR>
> Mar 1858 FALSE <BR>
> Apr 1858 FALSE <BR>
> May 1858 FALSE <BR>
> Jun 1858 FALSE <BR>
> <BR>
>> series[c(2,3)] <- T <BR>
>> head(series) <BR>
> [,1] <BR>
> Jan 1858 TRUE <BR>
> Feb 1858 TRUE # This worked as expected <BR>
> Mar 1858 TRUE # This worked as expected <BR>
> Apr 1858 FALSE <BR>
> May 1858 FALSE <BR>
> Jun 1858 FALSE <BR>
> <BR>
> <BR>
> <BR>
> _______________________________________________ <BR>
> R-SIG-Finance@stat.math.ethz.ch mailing list <BR>
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance <BR>
> -- Subscriber-posting only. <BR>
> -- If you want to post, subscribe first. <BR>
>
</BODY>
</HTML>