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") #------------------------------------------------- Thanks Pete -- View this message in context: http://r.789695.n4.nabble.com/zoo-column-names-tp3553939p3553939.html Sent from the R help mailing list archive at Nabble.com.
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
Gabor Grothendieck wrote:> > 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 > > ______________________________________________ > 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. >Thanks Gabor. Much appreciated. -- View this message in context: http://r.789695.n4.nabble.com/zoo-column-names-tp3553939p3554049.html Sent from the R help mailing list archive at Nabble.com.