[R] Strange Colnames
Gabor Grothendieck
ggrothendieck at myway.com
Fri Feb 25 13:39:57 CET 2005
Georg Hoermann <georg.hoermann <at> gmx.de> writes:
:
: Hello world,
:
: I am trying to create a matrix of lagged time series with the
: following code fragment (I know that I can use acf-function...).
: I want to set the variable/column name to something like
: "lag 1" etc. If I try to do it I get text like
: "lagtest.lagtest.lagtest.lag 1" where does this come from?
:
: After a conversion to a data.frame it works as expected.
: What did I miss?
:
: Thanks and greetings,
:
: Georg
: ==================
:
: > lagtest <- as.ts(seq(1:100)) ;
: > for (i in 1:4) {lagtest <- cbind(lagtest,lag(ts_test,i));
: colnames(lagtest)[i+1]<- paste("lag",i)}
: > colnames(lagtest)[1]<-"H_GW";
: > colnames(lagtest)
: [1] "H_GW" "lagtest.lagtest.lagtest.lag 1"
: "lagtest.lagtest.lag 2"
: [4] "lagtest.lag 3" "lag 4"
:
: # this works...
:
: > t5 <- as.data.frame(lagtest)
: > for (i in 1:4) {names(t5)[i+1] <- paste("var",i) }
: > names(t5)
: [1] "H_GW" "var 1" "var 2" "var 3" "var 4"
Here is something you could try:
# define lags and their names
lags <- 0:4
names(lags) <- c("G_HW", paste("lag", 1:4))
# build mts
do.call("cbind", lapply(lags, lag, x = lagtest))
More information about the R-help
mailing list