[R] [<- and indexing for zoo objects

Gabor Grothendieck ggrothendieck at gmail.com
Mon Nov 14 17:16:18 CET 2005


On 11/14/05, Brandt, T. (Tobias) <TobiasBr at taquanta.com> wrote:
>
>
> Hi
>
> I've been greatly enjoying the functionality the zoo package offers.
> However I've hit a snag with the following code
>
> > a <- zoo(matrix(1:10,5,2), 2001:2005)
> > a
>
> 2001  1  6
> 2002  2  7
> 2003  3  8
> 2004  4  9
> 2005  5 10
> > a[I(2003), 2]
>
> 2003 8
> > a[I(2003), 2] <- NA
> Error: subscript out of bounds
> >
>
> I've also tried
>
> > coredata(a[I(2003), 2]) <- NA
> Error: subscript out of bounds
> >
>
> but that doesn't work either.  I can of course do


Try this:

   window(a, 2003)[,2] <- NA

See

   ?"window<-.zoo"

for more info.




More information about the R-help mailing list