Iteratively change the names (column names) of xts timeseries objects

时间:2015-07-31 20:24:58

标签: r xts

I want to iteratively assign a vector of strings to the names (as in column names of a matrix) of the objects they represent. Example:

> Names
[1] "gs2"  "gs3"  "gs5"  "gs7"  "gs10"

The objects are xts timeseries of interest rates, for example:

> head(gs2,3)
           gs2Day
1976-06-01 0.0702
1976-07-01 0.0674
1976-08-01 0.0650
> class(gs2)
[1] "xts" "zoo"

So for this timeseries object I want to change the name from "gs2Day" to "gs2", but I want to do it iteratively over many time series. Something like this would be nice in a for loop (I know it's considered bad form and could use an apply instead),

> names(noquote(Names)[i]) = Names[i]

but of course it doesn't work. I've tried many approaches and none work. I suppose I could merge them into a matrix and iteratively name the columns, then strip off the columns into individual timeseries, but this seems rather crude.

1 个答案:

答案 0 :(得分:0)

这是OP说的对他们有用的东西,即使它不可再现:

Word