如何将每日时间序列转换为平均每周时间? [英] How to convert a daily times series into an averaged weekly?

查看:368
本文介绍了如何将每日时间序列转换为平均每周时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望(算术地)平均每天的数据,从而将我的每日时间序列转换为每周的时间序列。

I am wishing to (arithmetically) average daily data and thus convert my daily time series into a weekly one.

关注此线程:如何使用列来计算每周数据的平均值R?,我正在使用 xts 库。

Following this thread: How does one compute the mean of weekly data by column using R? , I am using the xts library.

# Averages daily time series into weekly time series
# where my source is a zoo object
source.w <- apply.weekly(source, colMeans)

我遇到的问题是它将星期二至下周一的数据取平均值。

The problem I am having is that it averages the series taking tuesday through next monday data.

我正在寻找将周一至周五的每日数据取平均值的选项。

I am searching for options to average my daily data from monday through friday.

有任何提示吗?

这里还有更多内容:

    # here is part of my data, from a "blé colza.txt" file


    24/07/2012  250.5   499
    23/07/2012  264.75  518.25
    20/07/2012  269.25  525.25
    19/07/2012  267 522.5
    18/07/2012  261.25  517
    17/07/2012  265.75  522.25
    16/07/2012  264.25  523.25
    13/07/2012  258.25  517
    12/07/2012  253.75  513
    11/07/2012  246.25  512.75
    10/07/2012  248 515
    09/07/2012  247 519.25
    06/07/2012  243.25  508.25
    05/07/2012  245 508.5
    04/07/2012  236 500.5
    03/07/2012  234 497.75
    02/07/2012  234.25  489.75
    29/06/2012  229 490.25
    28/06/2012  229.75  487.25
    27/06/2012  229.75  493
    26/06/2012  226.5   486
    25/06/2012  220 482.25
    22/06/2012  214.25  472.5
    21/06/2012  212 469.5
    20/06/2012  210.25  473.75
    19/06/2012  208 472.75
    18/06/2012  206.75  462.5
    15/06/2012  203 456.5
    14/06/2012  205.25  460.5
    13/06/2012  205.25  465.25
    12/06/2012  205.25  469
    11/06/2012  208 471.5
    08/06/2012  208 468.5
    07/06/2012  208 471.25
    06/06/2012  208 467
    05/06/2012  208 458.75
    04/06/2012  208 457.5
    01/06/2012  208 463.5
    31/05/2012  208 466.75
    30/05/2012  208 468
    29/05/2012  212.75  469.75
    28/05/2012  212.75  469.75
    25/05/2012  212.75  465.5



# Loads external libraries
library("zoo") # or require("zoo")
library("xts") # or require("xts")

# Loads data as a zoo object
source <- read.zoo("blé colza.txt", sep=",", dec=".", header=T, na.strings="NA",     format="%d/%m/%Y")

# Averages daily time series into weekly time series
# https://stackoverflow.com/questions/11129562/how-does-one-compute-the-mean-of-weekly-    data-by-column-using-r
source.w <- apply.weekly(source, colMeans) 


推荐答案

再看看我眼前的问题。

使用 xts 库可以直接使用。

# say you have xts object name 'dat'
ep <- endpoints(dat, on = 'weeks')                          # 
period.apply(x = dat, INDEX = ep, FUN = mean)

这篇关于如何将每日时间序列转换为平均每周时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆