R语言 : zoo rollmean 画移动平均线

help(package="zoo")

rollmean.R

library(zoo)
setwd("D:/test")
data <- read.csv("66001.txt", header=TRUE, sep=",")
class(data)
x <- as.Date(data$date, "%Y-%m-%d")
y <- zoo(data$jz5, x)
z <- na.trim(y)
head(z)
# 求移动平均值
ma1 <- rollapply(z, 30 , mean)
class(ma1)
plot(z, type="l", lwd=1,  main="660015", xlab="date", ylab="value", col="black")
lines(ma1, type="l", lwd=1, col="red")
grid()


参考书:[ R语言实战 (第2版) ] 第15章 时间序列 第319页


猜你喜欢

转载自blog.csdn.net/belldeep/article/details/78936064
zoo