如何在此时间序列数据中将名称添加到变量中。
gnp <- ts(cumsum(1 + round(rnorm(100), 2)),
start = c(1954, 7), frequency = 12)
plot(gnp) # using 'plot.ts' for time-series plot
答案 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)