这是数据框。
Year <- c(1901, 1911, 1921, 1931, 1941, 1951)
Population <- c(28445, 346222, 381046, 445606, 512069, 577635)
census <- cbind(Year, Population)
census <- as.data.frame(census)
census
Year Population
1 1901 28445
2 1911 346222
3 1921 381046
4 1931 445606
5 1941 512069
6 1951 577635
我希望它能改变为时间序列数据。
census.ts <- ts(census)
census.ts
Time Series:
Start = 1
End = 6
Frequency = 1
Year Population
1 1901 28445
2 1911 346222
3 1921 381046
4 1931 445606
5 1941 512069
6 1951 577635
时间间隔为10年,上面的代码似乎没有准确地读取时间序列数据。我该如何解决这个问题?提前谢谢!
答案 0 :(得分:1)
试试这个:
census.ts <- ts(census$Population, start = 1901, deltat = 10)
,并提供:
> census.ts
Time Series:
Start = 1901
End = 1951
Frequency = 0.1
[1] 28445 346222 381046 445606 512069 577635