[R] Strange Colnames
Georg Hoermann
georg.hoermann at gmx.de
Fri Feb 25 12:49:36 CET 2005
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"
>
More information about the R-help
mailing list