[R] zoo column names

Gabor Grothendieck ggrothendieck at gmail.com
Fri May 27 02:06:52 CEST 2011


On Thu, May 26, 2011 at 7:35 PM, Pete Brecknock <Peter.Brecknock at bp.com> wrote:
> I have a zoo object that contains 2 time series named "A-B" and "V1".
>
> When I create a third series "V2", the name of the "A-B" series is changed
> to "A.B".
>
> Although I could recreate the names for the 3 series I am wondering if there
> is a way of preventing the name change from happening  ( ... maybe an
> equivalent of the keep.names=TRUE statement on merge.zoo)?
>
>
> #------------------------------------------------
> library(zoo)
>
> # Create zoo data with required col names
> d = data.frame(c(10,20,30),c(1,2,3))
> names(d) = c("A-B", "V1")
> d.z = zoo(d,1:3)
>
> # Create new variable "V2"
> # col name changes from "A-B" to "A.B"
> d.z$V2 = d.z[,"V1"] *100
>
> # recreate col names
> names(d.z) = c(names(d),"V2")
> #-------------------------------------------------
>

Its doing a merge behind the scenes and this is a side effect of that.
 I agree that its strange behavior and will look at it.  In the
meantime try performing an explicit merge so that you can control it
using check.names:

> d.z <- zoo(cbind(`A-B` = c(10, 20, 30), V1 = c(1, 2, 3)))
> merge(d.z, V2 = 100*d.z$V1, check.names = FALSE)
  A-B V1  V2
1  10  1 100
2  20  2 200
3  30  3 300




-- 
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