我的时间序列数据如下所示:
data
Jan Feb Mar Apr May Jun Jul Aug Sep
1960 -10.3000 -7.1000 2.9000 18.0000 18.9000 29.5000 31.4000 28.0000 20.7000
1961 -1.8000 -4.2000 4.0000 13.2000 22.0000 23.4000 24.0000 23.4000 17.3000
1962 -12.1000 -3.1000 -0.1000 9.5000 22.9000 24.4000 26.4000 30.0000 21.2000
1963 -2.9000 -5.9000 5.4000 9.3000 21.0000 25.3000 27.9000 24.6000 21.4000
1964 -2.8000 -7.4000 2.2000 9.1000 17.6000 25.3000 25.1000 25.3000 18.0000
1965 -9.5000 1.0000 6.3000 14.3000 18.3000 24.7000 28.4000 26.7000 21.9000
1966 -5.4000 -2.7000 6.6000 14.3000 17.7000 24.2000 26.2000 25.3000 20.5000
1967 -8.1000 -0.6000 3.0000 13.8000 23.2000 23.8000 27.6000 24.3000 20.4000
我想以每月比例绘制数据,例如,我想绘制1960年至1967年1月份的数据。我尝试使用zoo
函数,但它不起作用。问题是即使在安装zoo
包之后,系统也似乎无法识别zoo
函数。错误消息如下所示:
> install.packages("zoo")
Installing package(s) into ‘C:/Users/skhanal2.RUSSELL/Documents/R/win-library/2.15’
(as ‘lib’ is unspecified)
trying URL 'http://streaming.stat.iastate.edu/CRAN/bin/windows/contrib/2.15/zoo_1.7-9.zip'
Content type 'application/zip' length 868277 bytes (847 Kb)
opened URL
downloaded 847 Kb
package ‘zoo’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘zoo’
The downloaded binary packages are in
C:\Users\skhanal2.RUSSELL\AppData\Local\Temp\RtmpCSHWVD\downloaded_packages
> test<-zoo(data,by="month")
**Error: could not find function "zoo"**
有没有人试图按月绘制时间序列数据?如果是这样,如果有人能帮我找到解决方案,我将不胜感激。此外,任何人都可以建议zoo
函数中的问题是什么?我使用R版本2.15.2,我在32位机器上使用Windows 7。谢谢!
答案 0 :(得分:1)
仅安装软件包是不够的。您还必须使用library()
命令将其加载到内存中,例如library(zoo)
。一旦你正确加载动物园包......
test<-zoo(data,order.by=sort(data$year))
plot(test)
#or
plot(test[,c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep")])