如何将一个间隔10年的趋势数据读入时间序列?
How to read a trend data with an interval of 10 years into time series?
这是数据框。
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年,上面的代码好像没有准确读取时间序列数据。我该如何解决这个问题?提前致谢!
试试这个:
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
这是数据框。
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年,上面的代码好像没有准确读取时间序列数据。我该如何解决这个问题?提前致谢!
试试这个:
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