[R] Coercing a character zoo to a numeric
Gabor Grothendieck
ggrothendieck at gmail.com
Tue Sep 27 14:17:55 CEST 2011
On Tue, Sep 27, 2011 at 5:56 AM, Ashim Kapoor <ashimkapoor at gmail.com> wrote:
> Dear R-helpers,
>
> It seems to me that a character zoo cannot be coerced to a numeric zoo.
> Below is a minimal example. Can someone tell me what I have done wrong?
>
>> z<-zoo(1:4,order.by=1:4)
>> coredata(z)<-as.character(coredata(z))
>> str(z)
> ‘zoo’ series from 1 to 4
> Data: chr [1:4] "1" "2" "3" "4"
> Index: int [1:4] 1 2 3 4
>> coredata(z)<-as.numeric(coredata(z))
>> str(z)
> ‘zoo’ series from 1 to 4
> Data: chr [1:4] "1" "2" "3" "4"
> Index: int [1:4] 1 2 3 4
>
>
See ?zoo where it says that the zoo object may be "a numeric vector,
matrix or a factor".
Thus character is not supported although I suspect that a number of
operations continue to work anyways -- although evidently not that
one.
This seems to result in a numeric zoo object:
aggregate(z, identity, as.numeric)
although these sorts of computations with zoo objects that strictly
speaking are not legal are, of course, not officially supported.
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list