我正在电子表格中跟踪我的体重,但我想通过使用 R 来改善体验。我试图在 R 中找到一些有关时间序列分析的信息,但没有成功。
我这里的数据采用以下格式:
date -> weight -> body-fat-percentage -> water-percentage
e.g.
10/08/09 -> 84.30 -> 18.20 -> 55.3
我想做的事
plot
权重和指数移动平均线随时间的变化
我怎样才能做到这一点?
使用 R 将数据读入 Rx <- read.csv(filename)
。确保日期以字符类形式出现,权重以数字形式出现。
然后使用以下内容:
require(zoo)
require(forecast) # Needed for the ses function
x$date <- as.Date(x$date,"%m/%d/%Y") # Guessing you are using the US date format
x$weight <- zoo(x$weight,x$date) # Allows for irregular dates
plot(x$weight, xlab="Date", ylab="Weight") # Produce time plot
ewma <- as.vector(fitted(ses(ts(x$weight)))) # Compute ewma with parameter selected using MLE
lines(zoo(ewma,x$date),col="red") # Add ewma line to plot
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)