[R] [<- and indexing for zoo objects

Brandt, T. (Tobias) TobiasBr at Taquanta.com
Mon Nov 14 16:47:29 CET 2005


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
 
> ix <- which(index(a)==2003)
> a[ix, 2] <- NA
> a
          
2001  1  6
2002  2  7
2003  3 NA
2004  4  9
2005  5 10
> 

which gives me the desired result but I feel that a timeseries class should
really be able to handle the first syntax since with the workaround I'm back
to the way of doing things before I had timeseries objects.
 
Am I missing something or any comments?
 

Regards

Tobias Brandt
 

********************
Nedbank Limited Reg No 1951/000009/06
Directors: WAM Clewlow (Chairman)  Prof MM Katz (Vice-chairman)  ML Ndlovu (Vice-chairman)  TA Boardman (Chief Executive)
CJW Ball  MWT Brown  RG Cottrell  BE Davison  N Dennis (British)  MA Enus-Brey  Prof B de L Figaji  RM Head (British)
RJ Khoza  JB Magwaza  ME Mkwanazi  JVF Roberts (British)  CML Savage  GT Serobe  JH Sutcliffe (British)
Company Secretary: GS Nienaber     16.08.2005

This email and any accompanying attachments may contain confidential and proprietary information.  This information is private and protected by law and, accordingly, if you are not the intended recipient, you are requested to delete this entire communication immediately and are notified that any disclosure, copying or distribution of or taking any action based on this information is prohibited.

Emails cannot be guaranteed to be secure or free of errors or viruses.  The sender does not accept any liability or responsibility for any interception, corruption, destruction, loss, late arrival or incompleteness of or tampering or interference with any of the information contained in this email or for its incorrect delivery or non-delivery for whatsoever reason or for its effect on any electronic device of the recipient.

If verification of this email or any attachment is required, please request a hard-copy version.




More information about the R-help mailing list