[R] replacing elements of a zoo object

David Winsemius dwinsemius at comcast.net
Mon Aug 29 21:09:09 CEST 2011


On Aug 29, 2011, at 3:02 PM, Gene Leynes wrote:

> Although I'm not sure what you're talking about with pop-up windows...

I got (as expected) assignment,  so I assumed you were not expecting  
assignment.

>
> Weird, this is what I'm getting in either R 2.13.0 or R 2.12.0:
>
> > library(zoo)
> Warning: package 'zoo' was built under R version 2.13.1
> > 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
> Error in dimnames(x) <- dn :
>   length of 'dimnames' [1] not equal to array extent

I get
 > x
2001-01-02 2001-01-03 2001-01-04 2001-01-05 2001-01-06
          1          2          3          0          5

As did another. So you are the odd man out and the burden is on you to  
show why updating to a current version does not solve your broken  
installation.

-- 
David.

> >
> >
>
>
> Thank you for any insight
>
>
> On Mon, Aug 29, 2011 at 1:53 PM, David Winsemius <dwinsemius at comcast.net 
> > wrote:
>
> On Aug 29, 2011, at 2:45 PM, Gene Leynes 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.
>
> It did exactly what I expected it to do. What was the "this" that  
> you think was bad? I hope you are not asking that R ask users to  
> confirm every assignment with a popup window.
>
> -- 
>
> David Winsemius, MD
> West Hartford, CT
>
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list