按年和月汇总数据(和时间序列图)

时间:2016-09-05 10:21:55

标签: r graph time-series aggregate

我需要您按年份和月份汇总数据的帮助,并绘制图表是否可行。

我的数据位于csv文件中,并且某种程度上数据不在当前显示1个频率且未正确聚合的良好数据帧中。

这是数据的前几部分:

 YEAR   Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
1 1964 131.4 121.8 125.7 131.9 138.5 144.1 150.5 161.6 160.3 149.7 142.1 139.1
2 1965 133.4 127.9 129.9 132.3 141.9 152.1 156.2 157.1 159.8 149.5 146.6 130.4
3 1966 125.6 128.1 138.5 140.9 142.5 152.5 154.8 175.3 167.9 154.7 137.4 135.4
4 1967 123.8 121.5 120.4 130.2 138.2 147.8 152.3 148.0 155.2 152.8 142.9 127.4
5 1968 120.2 112.9 113.1 117.4 122.9 133.0 150.3 161.3 156.4 150.4 141.7 140.4
6 1969 128.2 118.2 129.6 137.4 151.1 150.3 156.0 162.1 155.5 148.7 139.1 127.1
7 1970 126.1 123.9 122.4 133.0 144.4 146.8 151.8 157.3 152.1 147.9 146.1 134.5
8 1971 131.3 129.8 127.5 132.1 140.3 148.4 153.6 165.1 168.4 150.2 137.8 122.7
9 1972 132.0 131.6 128.2 132.9 142.0 153.7 166.4 164.7 156.4 146.9 144.8 136.2

正如你所看到的,我从1964年1月开始使用它,我试图用这些数据制作时间序列图。

以下是我使用的代码:

meansealevel<- ts(test_jeju, frequency=12, start=c(1964,1))

并且失败了,我发现数据的频率是1。 谁知道如何正确聚合这些数据以制作正确的时间序列图?

1 个答案:

答案 0 :(得分:1)

试试这个

test_jeju <- read.table(header=T, text=" YEAR   Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
1 1964 131.4 121.8 125.7 131.9 138.5 144.1 150.5 161.6 160.3 149.7 142.1 139.1
2 1965 133.4 127.9 129.9 132.3 141.9 152.1 156.2 157.1 159.8 149.5 146.6 130.4
3 1966 125.6 128.1 138.5 140.9 142.5 152.5 154.8 175.3 167.9 154.7 137.4 135.4
4 1967 123.8 121.5 120.4 130.2 138.2 147.8 152.3 148.0 155.2 152.8 142.9 127.4
5 1968 120.2 112.9 113.1 117.4 122.9 133.0 150.3 161.3 156.4 150.4 141.7 140.4
6 1969 128.2 118.2 129.6 137.4 151.1 150.3 156.0 162.1 155.5 148.7 139.1 127.1
7 1970 126.1 123.9 122.4 133.0 144.4 146.8 151.8 157.3 152.1 147.9 146.1 134.5
8 1971 131.3 129.8 127.5 132.1 140.3 148.4 153.6 165.1 168.4 150.2 137.8 122.7
9 1972 132.0 131.6 128.2 132.9 142.0 153.7 166.4 164.7 156.4 146.9 144.8 136.2")
meansealevel<- ts(as.vector(t(test_jeju[,-1])), frequency=12, start=c(1964,1))
plot(meansealevel)

enter image description here