r - R中的时间序列

标签 r time-series

我正在电子表格中跟踪我的体重,但我想通过使用 R 来改善体验。我试图在 R 中查找一些有关时间序列分析的信息,但没有成功。

我这里的数据采用以下格式:

date -> weight  -> body-fat-percentage  -> water-percentage

例如

10/08/09 -> 84.30 -> 18.20 -> 55.3

我想做什么

绘制权重和指数移动平均线与时间的关系

我怎样才能实现这一目标?

最佳答案

使用 x <- read.csv(filename) 将数据读入 R 。确保日期以字符类形式出现,权重以数字形式出现。
然后使用以下内容:

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

关于r - R中的时间序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1548913/

相关文章:

python - Pandas 中的采样从 1 个月减少到几个月

r - 避免 ggplot2 部分剪切轴文本

r - r 中的决斗树形图(在 r 中将树形图背靠背放置)

c++ - 将 double * 转换为 std::vector<double> 给我错误

python - 关于scipy.signal中savgol_filter函数参数的一些疑问

java - Postgresql:创建一个使用generate_series的查询,其间隔正确考虑DST更改并在真实日历日上展平

r - 绘制每毫秒的时间序列

python - Pandas 滚动窗口 - datetime64[ns] 未实现

r - R 列表是广义向量吗?

r - 在 x 轴刻度值上对齐不同宽度的图