如何在R中的此时间序列数据中添加名称

时间:2018-07-04 19:46:17

标签: r time series

如何在此时间序列数据中将名称添加到变量中。

gnp <- ts(cumsum(1 + round(rnorm(100), 2)),
          start = c(1954, 7), frequency = 12)
plot(gnp) # using 'plot.ts' for time-series plot

1 个答案:

答案 0 :(得分:1)

It needs to have 2 dimensions in order that the series have a name. Change its dimensions to n x 1 and add a column name. Note that the vertical axis of the plot now refers to the new column name X.

dim(gnp) <- dim(matrix(gnp))
colnames(gnp) <- "X"
plot(gnp)