[R] replacing elements of a zoo object

David Winsemius dwinsemius at comcast.net
Mon Aug 29 22:00:45 CEST 2011


On Aug 29, 2011, at 3:33 PM, R. Michael Weylandt wrote:

> Hmm, I don't know what this means as trouble shooting, but I get the  
> following:
>
> snipped


>          4
> > x[as.Date('2001-01-05')] = 0
> > x
> Error in dimnames(x) <- dn :
>   length of 'dimnames' [1] not equal to array extent
> > str(x)
> ‘zoo’ series from 2001-01-02 to 2001-01-06
>   Data: num [1:11327] 1 2 3 4 5 NA NA NA NA NA ...
                  ^^^^^^

>   Index: Class 'Date'  num [1:5] 11324 11325 11326 11327 11328
> >

 > difftime(as.Date("1970-01-01"), as.Date("2001-01-05"))
Time difference of -11327 days

Notice that some buggy interaction of mismatched package versions  
managed to get the internal integer representation of a Date classed  
variable confused with a length. I see this as of trifling interest at  
best. That nice police officer over there is telling us: "Nothing to  
see here folks, move on; please stop blocking the sidewalk."

>
>
> Obviously this is hard for anyone to troubleshoot if you can't  
> reproduce it. I get the same error in R versions 12.0 and 13.0  
> (although I don't get the "warning zoo was built under R 13.1"  
> warning when I use zoo in R 12.0)
>
>
>
> On Mon, Aug 29, 2011 at 2:07 PM, Gene Leynes <gleynes+r at gmail.com>  
> wrote:
> Michael,
>
> By the way, although I replied to David's email, I was responding to  
> you as well.  Your results were exactly what I was expecting, but I  
> didn't get your results.
>
>
>
> On Mon, Aug 29, 2011 at 1:51 PM, R. Michael Weylandt <michael.weylandt at gmail.com 
> > wrote:
> How exactly do you mean it doesn't work? Copied from my GUI:
>
> > x = zoo(1:5, as.Date('2001-01-01')+1:5)
> > x[as.Date('2001-01-05')]
> 2001-01-05
>          4
> > x[as.Date('2001-01-05')] = 0
> > x
> 2001-01-02 2001-01-03 2001-01-04 2001-01-05 2001-01-06
>          1          2          3          0          5
>
> (Those actually line up correctly on my machine..)
>
> Michael Weylandt
>
> On Mon, Aug 29, 2011 at 2:45 PM, Gene Leynes <gleynes+r at gmail.com>  
> wrote:
> Why doesn't this work?
>
> x = zoo(1:5, as.Date('2001-01-01')+1:5)
> x[as.Date('2001-01-05')]
> x[as.Date('2001-01-05')] = 0
> x
>
>
> I think this is especially bad because it doesn't cause an error.   
> It lets
> you do something to x, but then you can't see x again to see what it  
> did.
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list